简单的字符串处理,使用struct和map,使得做起来十分简单
#include <iostream>
#include <string>
#include <map>
using namespace std;
struct person
{
string name;
string id;
};
int main()
{
int n,i;
map<string,string> MJ;
while(cin>>n&&n!=0)
{
MJ.clear();
person *pm=new person[n];
for(i=0;i<n;i++)
{
cin>>pm[i].name>>pm[i].id;
}
for(int j=0;j<n-1;j++)
for(int k=j+1;k<n;k++)
{
if(pm[k].id==pm[j].id)
MJ.insert(pair<string,string>(pm[j].name,pm[k].name));
}
map<string,string>::iterator iter;
for(iter=MJ.begin();iter!=MJ.end();iter++)
cout<<iter->second<<" is the MaJia of "<<iter->first<<endl;
cout<<endl;
}
return 0;
}