#include<bits/stdc++.h>
using namespace std;
struct node
{
struct node *next[26];
int cot;
} a[1000000];
node *now=a;
int insert(node * &root,char *str)
{
if(!root)
root=now++;
node *p=root;
while(*str)
{ //printf("sssss");
int i=*str-'a';
if(!p->next[i])
p->next[i]=now++;
p=p->next[i];
str++;
}
p->cot++;
return p->cot;
}
int main()
{memset(a, 0, sizeof(node) * 1000000);
int n;
scanf("%d",&n);
char str[11];
char t[11];
int ans=0;
node *root;
root=NULL;
while(n--)
{
scanf("%s",str);
int temp=insert(root,str);
if(temp>ans)
{
strcpy(t,str);
ans=temp;
}
}
printf("%s %d\n",t,ans);
return 0;
}
字典树:动物统计加强版 (nyoj)
最新推荐文章于 2018-09-25 08:48:30 发布