[Sicily online] 1027. MJ, nowhere to hide

Source: Internet
Author: User
/* Use two maps to implement constraintstime limit: 1 secs, memory limit: 32 mbdescriptionon 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. inputthe 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_addressbbs_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 indicate 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 shocould be terminated by n = 0. outputfor each test case, output n/2 lines of the following format: "Mj_id is the Majia of main_id" they shoshould 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 input8inkfish 192.168.29.24zhi 192.168.29.235magicpig 192.168.50.170pegasus 192.168.29.235iamcs 202.116.77.?finalbob 192.168.29.24tomek =192.168.50.1704mmmmmm =192.168.4 9.161 llll has been outputtomek is the Majia of Alibaba is the Majia of magicpigpegasus is the Majia of Zhi llll is the Majia of Alibaba is the Majia of Mmmmmmmm */# include <iostream> # include <fstream> # include <vector> # include <string> # include <algorithm> # include <cmath> # include <list> # include <map> # include <string. h> using namespa Ce STD; int main () {int N; while (CIN> N & N) {Map <string, string> ip2id; Map <string, string> result; for (INT I = 0; I <n; I ++) {string ID, IP; CIN >>> ID >> IP; Map <string, string> :: iterator ite = ip2id. find (IP); If (ITE = ip2id. end () {ip2id. insert (make_pair (IP, ID);} else {result. insert (make_pair (ITE-> second, ID); ip2id. erase (ITE) ;}// end formap <string, string >:: iterator ite = result. begin (); For (; ite! = Result. end (); ite ++) cout <ite-> second <"is the Majia of" <ite-> first <Endl; cout <Endl ;} // end n}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.