zoukankan      html  css  js  c++  java
  • poj 2503 Babelfish

    一个简单的单词的翻译题。我使用的字典;

    因为问题输入 ,,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; }




    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    css 图片的无缝滚动
    有时间研究下这个
    js的类数组对象
    js的this什么时候会出现报错
    js前端分页
    js队列
    js前端处理url中的参数为对象
    随机看的一点代码
    js的callee和caller方法
    js的Object和Function
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4713805.html
Copyright © 2011-2022 走看看