Dictionary tree problems (MAP water available)
I will give you a dictionary and ask you to translate a passage.
Find the corresponding link and then output it. The dictionary tree is used to return the first few unknown words that appear and then correspond to each other.
You can use map to water the past.
Trie:
#include<cstdio>#include<cstring>#include<string>#include<queue>#include<algorithm>#include<map>#include<stack>#include<iostream>#include<list>#include<set>#include<cmath>#define INF 0x7fffffff#define eps 1e-6#define LL long longusing namespace std;struct Trie{ int word[100001][26]; int sz,cot; int ex[1000001]; Trie() { sz=1; cot=1; memset(word,0,sizeof(word)); memset(ex,0,sizeof(ex)); } int insert(char *s) { int u=0,c,len=strlen(s); for(int i=0; i<len; i++) { c=s[i]-'a'; if(!word[u][c]) word[u][c]=sz++; u=word[u][c]; } if(ex[u]==0)ex[u]=cot++; return ex[u]; } int search(char *s) { int u=0,c,len=strlen(s); for(int i=0;i<len;i++) { c=s[i]-'a'; if(word[u][c]) u=word[u][c]; else return 0; } return ex[u]; }}wo;char str[100001][11];int main(){ char tmp[25]; char a[11],b[11]; while(gets(tmp),*tmp) { sscanf(tmp,"%s %s",a,b); int m=wo.insert(b); sscanf(a,"%s",str[m]); } while(scanf("%s",a)!=EOF) { int m=wo.search(a); if(m==0)puts("eh"); else puts(str[m]); }}
Map:
#include<cstdio>#include<cstring>#include<string>#include<queue>#include<algorithm>#include<map>#include<stack>#include<iostream>#include<list>#include<set>#include<cmath>#define INF 0x7fffffff#define eps 1e-6#define LL long longusing namespace std;map<string,string>word;int main(){ string a; char str[51]; char sa[11],sb[11]; while(gets(str),*str) { sscanf(str,"%s %s",sa,sb); word[sb]=sa; } while(cin>>a) { if(word.find(a)==word.end()) puts("eh"); else cout<<word[a]<<endl; }}