找马甲……很简单的问题,用string+map就可以完美解决。
Run Time: 0sec
Run Memory: 312KB
Code length: 915Bytes
SubmitTime: 2011-07-2310:28:16
// Problem#: 1027
// Submission#: 839489
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <iostream>
#include <string>
#include <map>
using namespace std;
struct Info {
string id;
string ip;
};
int main()
{
int n;
int i, j;
Info info[ 21 ];
while ( true ) {
cin >> n;
if ( n == 0 )
break;
map<string, string> m;
for ( i = 1; i <= n; i++ )
cin >> info[ i ].id >> info[ i ].ip;
for ( i = 1; i <= n; i++ ) {
for ( j = i + 1; j <= n; j++ ) {
if ( info[ i ].ip == info[ j ].ip ) {
m[ info[ i ].id ] = info[ j ].id;
break;
}
}
}
for ( map<string, string>::iterator i = m.begin(); i != m.end(); i++ )
cout << i->second << " is the MaJia of " << i->first << endl;
cout << endl;
}
return 0;
}