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; }
原文地址:https://www.cnblogs.com/zhousysu/p/5483671.html