HDU 1072 What Are You Talking About

原题目链接HDU1075


分类

HDU map STL


题意

给出一个“翻译-原文”的对应表,然后给出句子,要把句子中的原文都翻译出来。


样例输入输出

Sample Input

START 
from fiwo 
hello difh 
mars riwosf 
earth fnnvk 
like fiiwj 
END 
START 
difh, i'm fiwo riwosf. 
i fiiwj fnnvk! 
END

Sample Output

hello, i'm from mars. 
i like earth!

想法

map映射,因为给了时间5s,直接写也可以写对,还有一种方法是tire树,但是不熟悉,而且很模板麻烦,有3


代码

1825ms

#include<bits/stdc++.h>
using namespace std;
string a,b;
char s[11111]; 
map<string,string> mp;

int main() {
    //freopen("in.txt","r",stdin);
    cin >> a;//第一个start 
    while(cin >> a){
        if(a=="END") break;
        cin >> b;
        mp[b] = a;
    }
    cin >> a;//第二个start 
    getchar();
    while(1){
        gets(s);//gets录入一行 
        if(strcmp(s,"END")==0) break;
        int len = strlen(s);
        a = "";
        for(int i=0;i<len;i++){
            if(islower(s[i])){
                a+=s[i];
            }else{
                if(mp.find(a)!=mp.end()){
                    cout << mp[a];
                }else{
                    cout << a;
                }
                cout << s[i];
                a = "";
            }
        }
        cout << endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40456064/article/details/84195954
今日推荐