首页 > 其他 > 详细

J - Misha and Changing Handles

时间:2020-02-29 09:33:22      阅读:72      评论:0      收藏:0      [点我收藏+]

又是一个思维题,正着不好吗、反着来

https://codeforces.com/problemset/problem/501/B

改名字,n次修改记录,输出是

好几个下面的:

老名字  新名字

#include<bits/stdc++.h> 
#define N 10
#define endl ‘\n‘ 
#define _for(i,a,b) for(int i=a;i<b;i++)
using namespace std;
typedef long long ll;  
map<string,string> Map; 
set<string> Set; 
int main(){    
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);    
    int n; cin>>n;  
    while(n--){
        string a,b; int cnt=0;
        cin>>a>>b;
        if(Set.count(a)){
            Set.erase(a),Set.insert(b);
            Map[b]=Map[a];
        }
        else{ 
            Set.insert(b);
            Map[b]=a;
        }
    }
    cout<< Set.size() <<endl;
    for(auto New : Set){
        cout<<Map[New]<< <<New<<endl;
    }
    return 0;
} 

 

J - Misha and Changing Handles

原文:https://www.cnblogs.com/SunChuangYu/p/12381313.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!