mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
56 lines
991 B
C++
56 lines
991 B
C++
|
/// HDU 1251
|
||
|
#include <cstdio>
|
||
|
#include <cstdlib>
|
||
|
#include <cstring>
|
||
|
using namespace std;
|
||
|
|
||
|
struct node
|
||
|
{
|
||
|
node* next[26];
|
||
|
int val;
|
||
|
node(){val=0;memset(next,0,sizeof(next));}
|
||
|
};
|
||
|
char buffer[1024];
|
||
|
node _root;
|
||
|
node* root=&_root;
|
||
|
int main()
|
||
|
{
|
||
|
while(gets(buffer))
|
||
|
{
|
||
|
if(strlen(buffer)<1)
|
||
|
{
|
||
|
break;
|
||
|
}
|
||
|
char* p=buffer;
|
||
|
node* np=root;
|
||
|
while(*p!=0)
|
||
|
{
|
||
|
if(np->next[*p-'a']==NULL) np->next[*p-'a']=new node;
|
||
|
np=np->next[*p-'a'];
|
||
|
p++;
|
||
|
np->val++;
|
||
|
}
|
||
|
}
|
||
|
while(gets(buffer))
|
||
|
{
|
||
|
char* p=buffer;
|
||
|
node* np=root;
|
||
|
bool undone=true;
|
||
|
while(*p!=0)
|
||
|
{
|
||
|
if(np->next[*p-'a']==NULL)
|
||
|
{
|
||
|
printf("0\n");undone=false;break;
|
||
|
}
|
||
|
np=np->next[*p-'a'];
|
||
|
p++;
|
||
|
}
|
||
|
if(undone)
|
||
|
{
|
||
|
printf("%d\n",np->val);
|
||
|
}
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|