http://acm.nyist.net/JudgeOnline/status.php?pid=290
来源:互联网 发布:大数据培训机构排名 编辑:程序博客网 时间:2024/06/03 20:34
动物统计加强版
时间限制:3000 ms | 内存限制:150000 KB
难度:4
描述
在美丽大兴安岭原始森林中存在数量繁多的物种,在勘察员带来的各种动物资料中有未统计数量的原始动物的名单。科学家想判断这片森林中哪种动物的数量最多,但是由于数据太过庞大,科学家终于忍受不了,想请聪明如你的ACMer来帮忙。
输入
第一行输入动物名字的数量N(1<= N <= 4000000),接下来的N行输入N个字符串表示动物的名字(字符串的长度不超过10,字符串全为小写字母,并且只有一组测试数据)。
输出
输出这些动物中最多的动物的名字与数量,并用空格隔开(数据保证最多的动物不会出现两种以上)。
样例输入
10
boar
pig
sheep
gazelle
sheep
sheep
alpaca
alpaca
marmot
mole样例输出
时间限制:3000 ms | 内存限制:150000 KB
难度:4
描述
在美丽大兴安岭原始森林中存在数量繁多的物种,在勘察员带来的各种动物资料中有未统计数量的原始动物的名单。科学家想判断这片森林中哪种动物的数量最多,但是由于数据太过庞大,科学家终于忍受不了,想请聪明如你的ACMer来帮忙。
输入
第一行输入动物名字的数量N(1<= N <= 4000000),接下来的N行输入N个字符串表示动物的名字(字符串的长度不超过10,字符串全为小写字母,并且只有一组测试数据)。
输出
输出这些动物中最多的动物的名字与数量,并用空格隔开(数据保证最多的动物不会出现两种以上)。
样例输入
10
boar
pig
sheep
gazelle
sheep
sheep
alpaca
alpaca
marmot
mole样例输出
sheep 3
代码:
#include <iostream> #include <cstdio> #include <string.h> #include <malloc.h>#define FOR(i,s,t) for(int i=(s);i<=(t);++i) using namespace std; struct Tire { int count;struct Tire *tire[26]; }*a; void init() { a=(Tire*)malloc(sizeof(Tire)); FOR(i,0,25)a->tire[i]=NULL; } int insert(char ch[]) { int length=strlen(ch); Tire *head=a; FOR(i,0,length-1){ int k=(int)(ch[i]-97); if(head->tire[k]==NULL) { head->tire[k]=new Tire; head=head->tire[k]; head->count=0; for(int j=0;j<26;++j) head->tire[j]=NULL; } elsehead=head->tire[k]; } head->count++; return head->count; } int main() { char s[10],ss[10]; init(); int n; scanf("%d",&n); int max=0,sum=0; while(n--) { scanf("%s",s); sum=insert(s); if(sum>max) { strcpy(ss,s); max=sum; } } printf("%s %d\n",ss,max); return 0;}
- http://acm.nyist.net/JudgeOnline/status.php?pid=290
- http://acm.nyist.net/JudgeOnline/problem.php?pid=290
- http://acm.nyist.net/JudgeOnline/problem.php?pid=434
- http://acm.nyist.net/JudgeOnline/problem.php?pid=13
- http://acm.nyist.net/JudgeOnline/problem.php?pid=239
- http://acm.nyist.net/JudgeOnline/problem.php?pid=129
- http://acm.nyist.net/JudgeOnline/problem.php?pid=431
- http://acm.nyist.net/JudgeOnline/problem.php?pid=301
- http://acm.nyist.net/JudgeOnline/problem.php?pid=451
- http://acm.nyist.net/JudgeOnline/problem.php?pid=459
- http://acm.nyist.net/JudgeOnline/problem.php?pid=20
- http://acm.nyist.net/JudgeOnline/problem.php?pid=267
- http://acm.nyist.net/JudgeOnline/problem.php?pid=305
- http://acm.nyist.net/JudgeOnline/problem.php?pid=309
- http://acm.nyist.net/JudgeOnline/problem.php?pid=325
- http://acm.nyist.net/JudgeOnline/problem.php?pid=420
- http://acm.nyist.net/JudgeOnline/problem.php?pid=488
- http://acm.nyist.net/JudgeOnline/problem.php?pid=150
- linux grep命令参数及用法详解---管道命令grep
- Oracle数据库常用函数(二)
- php ini set 相关的设置项有四个变更域
- 集合
- Android数据缓冲区和数据流的学习总结(BufferedWriter、BufferedOutputStream和FileOutputStream)
- http://acm.nyist.net/JudgeOnline/status.php?pid=290
- 两款实用免费的文档免积分下载工具,支持百度文库、豆丁网等
- Python debug 模块之pdb--(一)
- ubuntu屏幕截图工具:scrot,可截鼠标拖曳的矩形区域图形
- 输出1~100,每五个显示在一行
- 关于Apple AppStore上的问题请在这里回帖留言
- 存储过程--sqlerver2000从已知表导出insert语句
- ..如何表示跟当前目录的关系
- Asp.Net平台下的图片在线裁剪功能的实现