---
# System prepended metadata

title: UVa 10882 - Babelfish
tags: [林基成-C++, UVA code, cpp, Awwwolf的刷題之路]

---

# UVa 10882 - Babelfish
## Online Judge
![](https://i.imgur.com/BLZTxar.png)

## 解題思路
就把foreign當作key，message放入就好，沒什麼特別的
## 解題中出現的bug
1.用getline讀整行的字串進來後，才能用!=""去判斷是否讀到空行。
## Code
```cpp=
#include <iostream>
#include <sstream>
#include <string>
#include <map>
using namespace std;

int main()
{
    map<string, string> dictionary;
    string message, foreign, input;
    while(getline(cin,input)&&input!="")
    {
        stringstream ss(input);
        ss >> message >> foreign;
        dictionary[foreign] = message;
    }
    while(getline(cin,input)&&input!="")
    {
        auto it = dictionary.find(input);
        if(it!=dictionary.end())
            cout << it->second << endl;
        else
            cout << "eh" << endl;
    }
    return 0;
}
```
###### tags: `UVA code` `cpp` `林基成-C++` `Awwwolf的刷題之路`