UVA 10282 - Babelfish

题目大意:你到了一个陌生的地方,这个地方的单词和英语单词不一样。 每个英文单词都对应这一个当地的单词(都是一一对应,不会重复出现)。然后会给出一些当地的单词, 要你输出所对应的英文单词,未出现输出“eh"


解题思路:map的基本用法

#include <iostream>
#include <cstdio>
#include <string>
#include <map>
using namespace std;

int main() {
	map<string, string> word;
	char foreign[15], English[15], pair[50]; 
	while (gets(pair), pair[0]) {
		sscanf(pair, "%s%s", English, foreign);
		word[foreign] = English;
	}

	while (gets(foreign))
		word.find(foreign) != word.end() ? cout << word[foreign] << endl : cout << "eh" << endl;

	return 0;
}


你可能感兴趣的:(UVA 10282 - Babelfish)