0
点赞
收藏
分享

微信扫一扫

501B - Misha and Changing Handles

干自闭 2022-03-13 阅读 71

只能说这题体现了map的能力很强大

#include<bits/stdc++.h>

using namespace std;

const int N = 1010;

int main(){
    map<string,string> m;
	int n;
	cin>>n;
	string a,b;
	while(n--){
		cin>>a>>b;
		if(m.count(a)==0){
			m[a] = a;
		}
		m[b] = m[a];
		m.erase(a);	
	}
	cout<<m.size()<<endl;
	for(auto it=m.begin();it!=m.end();it++){
		cout<<it->second<<" "<<it->first<<endl;
	} 
  
}
举报

相关推荐

0 条评论