mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 1050.cpp
This commit is contained in:
parent
656dafdd2e
commit
6c3ff32521
47
QUSTOJ/1050.cpp
Normal file
47
QUSTOJ/1050.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
|
||||
char buff[1024];
|
||||
struct node
|
||||
{
|
||||
node* next[26];
|
||||
//int flag;/// If this is the end of some word
|
||||
int step;/// Depth.
|
||||
};
|
||||
node _root;
|
||||
node* root=&_root;
|
||||
int main()
|
||||
{
|
||||
int maxstep=0;
|
||||
int n;
|
||||
scanf("%d%*c",&n);
|
||||
for(int i=0;i<n;i++)
|
||||
{
|
||||
gets(buff);
|
||||
int L=strlen(buff);
|
||||
node* p=root;
|
||||
for(int j=0;j<L;j++)
|
||||
{
|
||||
if(p->next[buff[j]-'a'])
|
||||
{
|
||||
p=p->next[buff[j]-'a'];
|
||||
}
|
||||
else
|
||||
{
|
||||
node* q=new node;
|
||||
memset(q,0,sizeof(node));
|
||||
q->step=p->step;
|
||||
p->next[buff[j]-'a']=q;
|
||||
p=q;
|
||||
}
|
||||
}
|
||||
p->step++;
|
||||
maxstep=max(maxstep,p->step);
|
||||
}
|
||||
|
||||
printf("%d\n",maxstep);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user