Sicily 1027. MJ, Nowhere to Hide
来源:互联网 发布:php位运算 编辑:程序博客网 时间:2024/05/17 00:49
1027. MJ, Nowhere to Hide
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
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.
Sample Input
8inkfish 192.168.29.24zhi 192.168.29.235magicpig 192.168.50.170pegasus 192.168.29.235iamcs 202.116.77.131finalBob 192.168.29.24tomek 202.116.77.131magicduck 192.168.50.1704mmmmmm 172.16.72.126kkkkkk 192.168.49.161llllll 192.168.49.161nnnnnn 172.16.72.1260
Sample Output
tomek is the MaJia of iamcsfinalBob is the MaJia of inkfishmagicduck is the MaJia of magicpigpegasus is the MaJia of zhi llllll is the MaJia of kkkkkknnnnnn is the MaJia of mmmmmm
.
.
比较简单的方法应该就是用两个map做pair来用
#include<iostream>#include<map>#include<string>using namespace std;int main () {int n;map<string,string>out;map<string,string>in;while (cin >> n && n) {in.clear();out.clear();while (n--) {string id, ip;cin >> id >> ip;in.insert(make_pair(id, ip));map<string,string>::iterator it;for (it = in.begin(); it != in.end(); it++) {if (id != it->first && ip == it->second)out.insert(make_pair(it->first, id)); // map will sort automatically with it's key}}map<string,string>::iterator it;for (it = out.begin(); it != out.end(); it++) cout << it->second << " is the MaJia of " << it->first << endl;cout << endl;}return 0;}
- Sicily 1027. MJ, Nowhere to Hide
- [sicily online]1027. MJ, Nowhere to Hide
- Sicily 1027. MJ, Nowhere to Hide
- Sicily 1027. MJ, Nowhere to Hide
- sicily 1027. MJ, Nowhere to Hide
- Sicily 1027. MJ, Nowhere to Hide
- sicily 1027. MJ, Nowhere to Hide
- Sicily 1027. MJ, Nowhere to Hide
- sicily 1027. MJ, Nowhere to Hide
- sicily 1027. MJ, Nowhere to Hide
- Sicily 1027. MJ, Nowhere to Hide
- sicily-1027. MJ, Nowhere to Hide
- Sicily 1027 MJ, Nowhere to Hide
- sicily 1027 MJ,nowhere to hide
- sicily 1027 MJ, Nowhere to Hide
- sicily 1027 MJ, Nowhere to Hide
- 1027. MJ, Nowhere to Hide
- 1027. MJ, Nowhere to Hide
- Http协议学习笔记二
- final
- pygame_camera
- [LeetCode]ZigZag Conversion
- FIREFOX火狐最好用的Greasemonkey油猴脚本大集合!GOOGLE浏览器也可使用
- Sicily 1027. MJ, Nowhere to Hide
- 用宏构建自己的printf函数
- C++日志库笔记
- java mongodb
- flex 弹窗口嵌套iframe,移动窗体iframe内容不显示了问题处理
- NS2中调试工具 tcl-debug-2.0安装
- [历年IT笔试题]2014迅雷校园招聘笔试题
- Object-C学习笔记-基础篇-基础语法
- Java - 通过优酷网视频播放网址解析出Mp4格式的单个文件