HDU 1075 What Are You Talking About(用map进行翻译)

来源:互联网 发布:yy免费协议软件 编辑:程序博客网 时间:2024/06/03 22:47

题目地址:点击打开链接

题意:给出日语和英语的对应词典,输入一段日语,把日语翻译成英语,不是小写字母字符的不进行翻译,例如逗号,空格,没有对应英语的日语则直接输出日语

思路:字典树,二分查找,map映射,都可以做,效率逐渐降低,代码逐渐缩短,本题用map映射没超时

AC代码:

#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <cstring>#include <climits>#include <cmath>#include <cctype>//islower的头文件using namespace std;char a[20],english[15],martian[15];char b[3010];int main(){    int i;    map<string,string> map1;    scanf("%s",a);    while(scanf("%s",english) && strcmp(english,"END") != 0)    {        scanf("%s",martian);        map1[martian] = english;    }    scanf("%s",a);    string language = "";    getchar();//把残留在流中的空格吃掉,不然会被gets吃掉    while(gets(b) && strcmp(b,"END") != 0)    {        int n = strlen(b);        for(i=0; i<n; i++)        {            if(islower(b[i]))            {                language += b[i];            }            else            {                if(map1.find(language) != map1.end())                    cout<<map1[language];                else                    cout<<language;                language = "";                printf("%c",b[i]);            }        }        printf("\n");    }    return 0;}


1 0
原创粉丝点击