A(SDUT-OJ 2892)----字典树
来源:互联网 发布:淘宝商城正品店 编辑:程序博客网 时间:2024/05/17 00:51
A
Time Limit: 60ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
给出n(1<= n && n <= 2*10^6)个字符串,每个字符串只包含小写英文字母,且最多有五个。问这n个字符串中出现次数最多的有多少个。
输入
单组输入。第一行输入一个数字n,接下来n行,每行包含一个字符串。
输出
输出一个数字代表答案。
示例输入
5abaabbwabaz
示例输出
2
提示
来源
示例程序
- 提交
- 状态
- 讨论
#include <algorithm>#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <queue>#include <stack>#include <cmath>#include <map>using namespace std;//char s[100000][6];struct node{ int ans; struct node *next[26];};struct node *creat(){ int i; struct node *p; p=(struct node *)malloc(sizeof(struct node )); for(i=0;i<26;i++) { p->next[i]=NULL; } p->ans=NULL; return p;}void Insert(struct node *&root,char *s,int &Max){ if(root==NULL) { root=creat(); } if(s[0]!='\0') { Insert(root->next[s[0]-'a'],s+1,Max); } else { root->ans++; Max=max(root->ans,Max); }}int main(){ struct node *root=NULL; int n,Max=1,i,j; char s[6]; while(scanf("%d",&n)!=EOF) { for(i=0;i<n;i++) { scanf("%s",s); Insert(root,s,Max); } printf("%d\n",Max); } return 0;} /**************************************Problem id: SDUT OJ 2892 User name: mxjr130326刘继国 Result: Accepted Take Memory: 4508K Take Time: 20MS Submit Time: 2014-06-28 21:38:58 **************************************/
字典树是个很神奇的东西,建树,插入,查找,释放空间
0 0
- A(SDUT-OJ 2892)----字典树
- SDUT OJ 2892——字典树
- 字典树 SDUT OJ 2828
- SDUT OJ -2892 A
- SDUT-1500-(字典树)
- A+B Problem (sdut oj)
- SDUT 2828 字典树
- SDUT字典树
- SDUT OJ 2413 n a^o7 !
- SDUT 1500 Message Flood(字典树 && 模板)
- A(SDUT 2892)
- 【SDUT OJ 2610】 Boring Counting(主席树)
- light OJ -DNA Prefix (字典树)
- C语言实验——计算A+B(顺序结构)(sdut oj)
- C语言实验——从大到小输出a、b、c(选择结构)(sdut oj)
- A+B for Input-Output Practice (I) (sdut oj)
- A+B for Input-Output Practice (III) (sdut oj)
- A+B for Input-Output Practice (VII) (sdut oj)
- linux系统vi编辑文件时快捷键
- sdut 1500 Message Flood
- H2数据库导出导入数据方法
- c++下类成员函数的调用发生了啥(从汇编看)
- 数据存储之SharedPrefence
- A(SDUT-OJ 2892)----字典树
- Java学习整理之Java泛型
- 学习总结二十:坑爹呀,hadoop2源码编译
- fseek——解析1
- lua和C交互
- 高效程序员的45个习惯
- uva 10494(大数加减乘除取余一条龙模板代码) uva 10023 (大数开方)
- 数据存储之文件存储
- ZOJ-1159