CodeForces - 501B Misha and Changing Handles

https://vjudge.net/problem/CodeForces-501B

#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	string a,b;
	unordered_map<string,string> q;
	cin>>n;
	while(n--)
	{
		cin>>a>>b;
		int f=0;
		for(auto it:q)
		{
			if(it.second==a)
			{
				q[it.first]=b;
				f=1;
				break;
			}
		}
		if(!f)
			q[a]=b;
	}
	cout<<q.size()<<"\n";
	for(auto it:q)
		cout<<it.first<<" "<<it.second<<"\n";
	return 0;
}
posted @ 2021-08-22 20:33  斯文~  阅读(35)  评论(0)    收藏  举报

你好!