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