4371: GESP C++ 四级 3小杨的字典202312

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:12 解决:4

题目描述

样例输入 复制

2
abc a
d def
abc.d.d.abc.abcd.

样例输出 复制

a.def.def.a.UNK.

提示

#include<bits/stdc++.h>
using namespace std;
map<string, string> dict;
int main() {
    int N;
    cin >> N;
    while(N--) {
        string word1, word2;
        cin >> word1 >> word2;
        dict[word1] = word2;
    }
    string content, word = "";
    cin >> content, content += "\n";
    int m = content.length();
    for(int i = 0; i < m; i ++) {
        if (content[i] >= 'a' && content[i] <= 'z')
            word += content[i];
        else {
            if (word != "") {
                if (dict.count(word))
                    cout << dict[word];
                else cout << "UNK";
                word = "";
            }
            cout << content[i];
        }
    }
    return 0;
}