您的位置:首页 > 其它

HDU 1075 What Are You Talking About

2014-07-07 14:25 375 查看
字典树

看题库上说这是字典树,不过被我水过去了。

题意是说用对应的字典,翻译出火星文。

each line will contain at most 3000 characters.

看到这句话我就安心了。Time Limit: 10000/5000 MS (Java/Others)

果断用map 来水了。还真AC了。3296MS 。本来是想巩固一下字典树的,不过……。

#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<cmath>
#define INF 0x7fffffff
#define eps 1e-6
using namespace std;
map<string,string>word;

int main()
{
    string a,b;
    word.clear();
    while(cin>>a,a!="START");
    while(cin>>a,a!="END")
    {
        cin>>b;
        word[b]=a;
    }
    while(cin>>a,a!="START");
    char str[3001];
    gets(str);
    while(gets(str))
    {
        if(strcmp(str,"END")==0)return 0;
        int len=strlen(str);
        char s[3001],j=0;
        for(int i=0;i<len;i++)
        {
            if(str[i]>='a'&&str[i]<='z')
                s[j++]=str[i];
            else
            {
                s[j]='\0';j=0;
                b=s;
                if(word.find(b)==word.end())
                    cout<<b;
                else
                    cout<<word[b];
                printf("%c",str[i]);
            }
        }
        printf("\n");
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: