1027. MJ, Nowhere to Hide(寻找同IP名字并排序)

来源:互联网 发布:js控制网页打印区域 编辑:程序博客网 时间:2024/04/30 00:51
/*1027. MJ, Nowhere to Hide  大意:给出一系列名字-IP对,找出IP相同的配对名字,并且先出现的名字        为主名,而且按照主名排序 */#include <iostream>#include <string>#include <stdlib.h>#include <algorithm>using namespace std;#define MAX 10000struct info{   string name;   string ip;}data[MAX*2+1];struct Match{   string orig;   string maja;};Match match[MAX];bool cmp(Match a, Match b){   return a.orig < b.orig;     }int main(){       int n;        while(cin >> n && n)    {       for(int i=1; i<=n; i++)          cin >> data[i].name >> data[i].ip;       int matchIndex = 0;       for(int i=1; i<=n; i++)       {           for(int k=i+1; k<=n; k++)             if(data[k].ip != "" && data[i].ip  == data[k].ip)             {                match[matchIndex].orig = data[i].name;                match[matchIndex].maja = data[k].name;                matchIndex++;                data[i].ip = "";                data[k].ip = "";             }         }       sort(match, match+matchIndex, cmp);       for(int i=0; i<matchIndex; i++)         cout << match[i].maja << " is the MaJia of " << match[i].orig << endl;        cout << endl;        }    system("pause");    return 0;}

原创粉丝点击