1027. MJ, Nowhere to Hide

1027. 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. 

Input

The first line of each test cases is an even integer n (0<=n<=20), the number of posts on BBS.
Then n lines follow, each line consists of two strings:
BBS_ID IP_Address
BBS_ID means the ID who posts this post. BBS_ID is a string contains only lower case alphabetical characters and its length is not greater than 12. Each BBS ID appears only once in each test cases.
IP_Address is the IP address of that person. The IP address is formatted as “A.B.C.D”, where A, B, C, D are integers ranging from 0 to 255.
It is sure that there are exactly 2 different BBS IDs with the same IP address. The first ID appears in the input is the main ID while the other is the MJ of that person.
Your program should be terminated by n = 0.

Output

For each test case, output n/2 lines of the following format: “MJ_ID is the MaJia of main_ID”
They should be displayed in the lexicographical order of the main_ID.
Print a blank line after each test cases.
See the sample output for more details.


Problem Source

ZSUACM Team Member


好麻烦的方法。没手感。

#include <iostream>
#include <string>
using namespace std;

int main()
{
	int t;
	while(cin>>t&&t)
	{
		string arr[21][2],name[21][2];
		for(int k=0;k<t;k++)
			cin>>arr[k][0]>>arr[k][1];
		for(int i=0;i<t;i++)
		{
			for(int j=0;j<t-i-1;j++)
			{
				if(arr[j][1]>arr[j+1][1])
				{
					string temp1=arr[j][1];
					arr[j][1]=arr[j+1][1];
					arr[j+1][1]=temp1;
					string temp2=arr[j][0];
					arr[j][0]=arr[j+1][0];
					arr[j+1][0]=temp2;
				}
			}
		}
		int count=0;
		for(int i=0;i<t;i+=2)
		{
			name[count][0]=arr[i][0];
			name[count][1]=arr[i+1][0];
			count++;
		}
		for(int i=0;i<count;i++)
		{
			for(int j=0;j<count-i-1;j++)
			{
				if(name[j][0]>name[j+1][0])
				{
					string temp1=name[j][1];
					name[j][1]=name[j+1][1];
					name[j+1][1]=temp1;
					string temp2=name[j][0];
					name[j][0]=name[j+1][0];
					name[j+1][0]=temp2;
				}
			}
		}
		/*for(int i=0;i<count;i++)
			cout<<name[i][0]<<" "<<name[i][1]<<endl;*/
		for(int i=0;i<count;i++)
			cout<<name[i][1]<<" is the MaJia of "<<name[i][0]<<endl;
		cout<<endl;
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值