首页 > 其他 > 详细

HDU 1075 What Are You Talking About

时间:2014-07-08 14:42:25      阅读:287      评论:0      收藏:0      [点我收藏+]

字典树

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


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


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");
    }
}


HDU 1075 What Are You Talking About,布布扣,bubuko.com

HDU 1075 What Are You Talking About

原文:http://blog.csdn.net/dongshimou/article/details/37510045

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!