1024[MJ, Nowhere to Hide]

Description

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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值