/*
使用map可以轻松完成的寻找马甲的题目
注意!记得题目最后要求要在每一个case后面输出一个空行!
注意!记得include头文件!某些编译器不需要头文件照样跑函数,但是在sicily上就是A不了,例如algorithm
*/
/*
Run Time: 0secs
Run Memory: 312KB
*/
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef struct Pair{
string mainID;
string followID;
};
map<string, string> ipid;
vector<Pair> result;
int cmp(Pair left, Pair right){
return left.mainID < right.mainID;
}
int main()
{
int N;
cin >> N;
string id;
string ip;
while (N > 0){
for(int i=0; i<N; i++){
cin >> id >> ip;
map<string, string>::iterator iter = ipid.find(ip);
if(iter == ipid.end()){ //如果没有找到马甲,那他就是主号,将其存入map
ipid.insert(map<string, string>::value_type(ip,id));
}else{ //如果发现ip重复,那么当前这个就是马甲,将主号和马甲存入result
string mainid = iter->second;
Pair buf;
buf.mainID = mainid;
buf.followID = id;
result.push_back(buf);
}
}
sort(result.begin(), result.end(), cmp); //按照mainID进行排序
for(int i=0; i<result.size(); i++)
cout << result[i].followID << " is the MaJia of " << result[i].mainID << endl;
cout << endl;
ipid.clear();
result.clear();
cin >> N;
}
使用map可以轻松完成的寻找马甲的题目
注意!记得题目最后要求要在每一个case后面输出一个空行!
注意!记得include头文件!某些编译器不需要头文件照样跑函数,但是在sicily上就是A不了,例如algorithm
*/
/*
Run Time: 0secs
Run Memory: 312KB
*/
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef struct Pair{
string mainID;
string followID;
};
map<string, string> ipid;
vector<Pair> result;
int cmp(Pair left, Pair right){
return left.mainID < right.mainID;
}
int main()
{
int N;
cin >> N;
string id;
string ip;
while (N > 0){
for(int i=0; i<N; i++){
cin >> id >> ip;
map<string, string>::iterator iter = ipid.find(ip);
if(iter == ipid.end()){ //如果没有找到马甲,那他就是主号,将其存入map
ipid.insert(map<string, string>::value_type(ip,id));
}else{ //如果发现ip重复,那么当前这个就是马甲,将主号和马甲存入result
string mainid = iter->second;
Pair buf;
buf.mainID = mainid;
buf.followID = id;
result.push_back(buf);
}
}
sort(result.begin(), result.end(), cmp); //按照mainID进行排序
for(int i=0; i<result.size(); i++)
cout << result[i].followID << " is the MaJia of " << result[i].mainID << endl;
cout << endl;
ipid.clear();
result.clear();
cin >> N;
}
}