sicily 1027

来源:互联网 发布:数据分析师有哪些证书 编辑:程序博客网 时间:2024/04/27 22:32

开始写题解

很简单的map
#include<iostream>
#include<map>
using namespace std;
map<string,string>m;
map<string,string>p;
int main()
{
 int n;
 while(cin >> n && n)
  {
  m.clear();
  p.clear();
  string s1,s2;
  for(int i = 0; i < n; i++)
    {
    cin >> s1 >> s2;
    if(m.find(s2) == m.end())
      m[s2] = s1;
    else
      {
      map<string,string>::iterator it = m.find(s2);
      p[it->second] = s1;
      }
    }
   for(map<string,string>::iterator it = p.begin(); it != p.end(); it++)
     cout << it->second << " is the MaJia of " << it->first << endl;
   cout << endl;
  }
}