Description
Input
Output
Sample Input
5 aba abb w aba z
Sample Output
2
Hint
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct node{
int flag;
node *next[26];
};
int n,m;
int Max=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 *tree,char *b)
{
int ans;
int len = strlen(b);
node *p = tree;
for(int i = 0;i<len;i++)
{
ans = b[i]-'a';
if(p->next[ans]==NULL)
{
p->next[ans] = creat();
}
p = p->next[ans];
}
p->flag++;
if((p->flag) >Max)
Max = p->flag;
}
void freenode( node*tree)
{
for(int i = 0;i<n;i++)
{
if(tree->next[i]!=NULL)
{
freenode(tree->next[i]);
}
}
free(tree);
}
int main()
{
char a[2000000][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",Max);
freenode(p);
return 0;
}