一个简单的单词的翻译题。我使用的字典;
因为问题输入 ,,WA,WA,,,
眼泪。
#include <iostream> #include <string.h> #include <stdio.h> using namespace std; struct node{ int chile[26]; bool qq; char uu[11]; node() { qq=0; memset(chile,0,sizeof(chile)); memset(uu,0,sizeof(uu)); } }t[300001]; int index=1; void show(char *s,char *w) { int len=strlen(s); //int len1=strlen(s); int u=0; //int e; for(int i=0;i<len;i++) { int e=s[i]-'a'; if(t[u].chile[e]==0) {t[u].chile[e]=++index;} u=t[u].chile[e]; } //t[u].qq=1; strcpy(t[u].uu,w); //int o=u; //for(int j=u+1;j<u+len1;j++) //{ // int y=r[j-u-1]-'a'; // if(t[u].chile[y]==0) // { // t[j].chile[y]=sz++; // } // o=t[j].chile[y]; //} //t[0].qq=1; } void find(char* p) { int rr=0; int len=strlen(p); int g; for(int i=0;i<len;i++) { g=p[i]-'a'; if(t[rr].chile[g]==0) { printf("eh "); return ; } rr=t[rr].chile[g]; } printf("%s ",t[rr].uu); } int main() { char str[30],w[30],s[30]; int t; while(gets(str),str[0]) { //memset(s,0,sizeof(s)); int pos=0; //t=strlen(str); while(str[pos++]!=' '); str[pos-1]=0; //for(int i=0;i+pos<t;i++) // s[i]=str[i+pos]; memcpy(w,str,pos-1); show(str+pos,w);//把str+pos用数组取代就WA了。。
。
。<img alt="大哭" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/wail.gif" /> } while(gets(str)) find(str); return 0; }
版权声明:本文博客原创文章,博客,未经同意,不得转载。