Sicily 1027. MJ, Nowhere to Hide

//就是一个简单的字符串配对~~用map来解决很easy

#include <iostream> #include <map> #include <string> using namespace std; int main() { int n; while (cin>>n && n!=0) { string ip , name; string tmp; map<string,string> m; map<string,string>::iterator iter; map<string,string> ans; while(n--){ cin>> name >> ip; if ((iter = m.find(ip) )!= m.end()) { ans.insert(make_pair(iter->second, name+"is the MaJia of "+ iter->second)); m.erase(iter); }else m.insert(make_pair(ip, name)); } for(iter = ans.begin() ; iter != ans.end(); iter++) cout << iter->second << endl; cout << endl; } return 0; }

 

posted @ 2016-05-11 21:43  zhou23  阅读(206)  评论(0编辑  收藏  举报