On BBS, there is a familiar term called MJ (short for MaJia), which means another BBS ID of one person besides his/her main ID.
These days, a lot of ACMers pour water on the ACMICPC Board of argo. Mr. Guo is very angry about that and he wants to punish these guys. ACMers are all smart boys/girls, right? They usually use their MJs while pouring water, so Mr. Guo can not tell all the IDs apart. Unfortunately, the IP can not be changed, i.e, the posts of main ID and MJ of the same person has the same IP address, meanwhile, the IP addresses of different person is different. Assuming that each person has exactly one main ID and one MJ, by reading their posts on BBS, you then tell Mr. Guo whom each MJ belongs to.
**********************************************************************************************
意思就是把有相同IP的两个ID放在一起,第二个ID是第一个ID的马甲,第一个是原ID。
直接放代码吧。貌似有map的方法更简单一些。下面这个是最常规的。还有一点是,这个输出要排序后按首字母输出,所以应该在分完组之后再排序而不是分组前就排序。
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;
struct Student
{
string ID;
string IP;
};
struct StudentMJ
{
string ID;
string MJ;
};
bool comp( StudentMJ a, StudentMJ b )
{
return a.ID < b.ID;
};
int main()
{
Student S[20];
StudentMJ MJ[10];
int n;
string id, ip;
cin >> n;
while( n )
{
for( int i = 0; i < n; i++ )
cin >> S[i].ID >> S[i].IP;
int count = 0;
for( int i = 0; i < n-1; i++ )
for( int j = i+1; j < n; j++)
if( S[i].IP == S[j].IP )
{
MJ[count].ID = S[i].ID;
MJ[count].MJ = S[j].ID;
count++;
break;
}
sort(MJ,MJ+n/2,comp);
for( int i = 0; i < n/2; i++ )
cout << MJ[i].MJ << " is the MaJia of " << MJ[i].ID << endl;
cout << endl;
cin >> n;
}
return 0;
}