poj 2503 Babelfish

来源:互联网 发布:tsis交通仿真软件 编辑:程序博客网 时间:2024/06/06 05:06

一个简单的单词翻译的题,我是使用字典序做的;

由于输入的问题 ,,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\n");            return ;        }        rr=t[rr].chile[g];    }    printf("%s\n",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;}



0 0