http://acm.hdu.edu.cn/showproblem.php?pid=1075
#include <iostream>
#include <algorithm>
#include <cstring>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
using namespaceStd;
struct Node
{
int Flag;
Char Str[ the];
Node *Next[ -];
/* Node ()
{
Memset (Next, NULL, sizeof (next));
flag=0;
}*/
Node():Flag(0){Memset(Next,Null,sizeof(Next));};
};
Node *Head=NewNode();
void Connect(Char *A,Char *B)
{
Node *P=Head;
Node *p=new node ();
for(intI=0;A[I];I++)
{
int K=A[I]-' A ';
If (P -Next[K]==Null)
P -Next[K]=NewNode();
P=P -Next[K];
}
P -Flag=1;
strcpy(P -Str,B);
}
Char *Query(Char *S)
{
Node *P=Head;
for(intI=0;S[I];I++)
{
int K=S[I]-' A ';
If (P -Next[K]==Null)
return Null;
P=P -Next[K];
}
If (P -Flag==1)
return P -Str;
Else
return Null;
}
int Main()
{
Char M[ the],E[ the],B[3030],F[ the];
Gets(M);
while(scanf('%s ',M),strcmp(M,"END")!=0)
{
scanf('%s ',E);
Connect(E,M);
}
scanf('%s ',B);
GetChar();
while(Gets(B),strcmp(B,"END")!=0)
{
int I,J;
for(I=0;B[I];I++)
{
J=0;
while(B[I]>=' A '&&B[I]<=' Z ')
{
F[J++]=B[I];
I++;
}
F[J]=0;
Char *K=Query(F);
/*char k[15];
K=query (f); * *
If (K==0)
Printf('%s ',F);
else
Printf('%s ',K);
Printf("%c",B[I]);
}
Printf("\ n");
}
return 0;
}
Dictionary Tree HDU 1075 what is talking about