The main idea is to give two words, the previous word is the translation of the next word, that is, there is a key to the value of the mapping relationship, to enter the empty behavior sign end input correspondence, and then input the word output corresponding translation. So this problem can be solved by using the map container of C + + to establish correspondence relation.
The code is as follows:
1#include <iostream>2#include <map>3#include <cstdio>4#include <cstring>5 using namespacestd;6 intMain () {7 Charstr1[ *] ;8 Charkey[ *], value[ *] ;9map<string,string>Map_;Ten while(Gets (str1)) { One if(strcmp (STR1," /") ==0 ){ A Break ; - } -SSCANF (STR1,"%s%s", value, key);///reads from a string into data that matches the specified format the //Map_[key] = value; ///Two kinds of relationship of establishing key value can be; - Map_.insert (Make_pair (key, value)); - } - while(Gets (str1)) { +map<string,string>::iterator it;///iterators -it = Map_.find (STR1);///find out if this key is in MAP_ + if(It! = Map_.end ()) {///If you find Acout << it->second << Endl;///Output Key value at}Else{ -cout <<"EH"<< Endl;///otherwise output eh - } - } - return 0 ; -}
POJ 2503 Babelfish (c + +) (Map container)