A

nid=24#time" title="C、C++、go、haskell、lua、pascal Time Limit60ms Memory Limit 65536K java、python2、python3、ruby、perl Time Limit120ms Memory Limit 131072K" style="padding:0px; margin:0px; color:rgb(83,113,197); text-decoration:none">

Time Limit: 60ms   Memory limit: 65536K  有疑问?点这里^_^

题目描写叙述

给出n(1<= n && n <= 2*10^6)个字符串,每一个字符串仅仅包括小写英文字母。且最多有五个。

问这n个字符串中出现次数最多的有多少个。

输入

单组输入。

第一行输入一个数字n,接下来n行,每行包括一个字符串。

输出

输出一个数字代表答案。

演示样例输入

5
aba
abb
w
aba
z

演示样例输出

2

提示

 字段树,模板题

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
const int N = 20010;
using namespace std; struct node{
int flag;
node *next[26];
};
int n,m,ans = 0;
struct node *Creat()
{
node *p = new node;
for(int i = 0;i<26;i++)
{
p->next[i] = NULL;
}
p->flag = 0;
return p;
} void INsert(node *root,char *b)
{
int num;
int len = strlen(b);
node *p = root;
for(int i = 0;i<len;i++)
{
num = b[i]-'a';
if(p->next[num]==NULL)
{
p->next[num] = Creat();
}
p = p->next[num];
}
p->flag++;
if(p->flag > ans)
ans = p->flag;
} void FREE(struct node*root)
{
for(int i = 0;i<n;i++)
{
if(root->next[i]!=NULL)
{
FREE(root->next[i]);
}
}
free(root);
}
int main()
{
char a[N][50],s[50];
node *p; scanf("%d",&m);
p = Creat(); for(int i = 0;i<m;i++)
{
scanf("%s",s);
INsert(p,s);
}
printf("%d\n",ans);
FREE(p);
return 0;
} /**************************************
Result : Accepted
Take Memory : 4452K
Take Time : 10MS
Submit Time : 2014-06-21 16:13:31
**************************************/


最新文章

  1. 让你的站点也支持MarkDown
  2. 不可或缺 Windows Native (12) - C++: 引用类型
  3. 微软 PowerShell Script Explorer 满血复活,正式发布
  4. appstore 提交警告 - Missing iOS Distribution signing identity for xxxx
  5. 学习笔记--函数式线段树(主席树)(动态维护第K极值(树状数组套主席树))
  6. gcc编译C++程序
  7. C++中new的解说
  8. axis2调用webservice
  9. PHP判断远程图片或文件是否存在
  10. MySQL如何有效的存储IP地址及字符串IP和数值之间如何转换
  11. 关于极光推送Jpush的demo
  12. C# TCP 了解
  13. 【IOS 开发】Object-C 运算符
  14. spring+mybaits多数据源使用
  15. MongoDB中数组类型相关的操作
  16. springBoot整合jpa
  17. Jmeter连接Redis,获取Redis数据集
  18. #1014 : Trie树 HihoCoder(字典树)
  19. (大数 string easy。。。)P1781 宇宙总统 洛谷
  20. __NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0xb000000000000003

热门文章

  1. $P2121 拆地毯$
  2. Jsp入门小常识
  3. gerrit项目配置
  4. 关于学习C语言
  5. Unity学习-预制(四)
  6. 使用GCD验证码倒计时
  7. UDP网络程序实例
  8. 六时车主 App 隐私政策
  9. Java_Web三大框架之Hibernate 入门(一)
  10. centOS安装python3 以及解决 导入ssl包出错的问题