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;
}
本文来自博客园,作者:斯文~,转载请注明原文链接:https://www.cnblogs.com/zhiweb/p/15483250.html

浙公网安备 33010602011771号