Sicily 1027. MJ, Nowhere to Hide

31 篇文章 0 订阅
/*
使用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;

    } 


    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值