解题思路
const int N =1010;
//字符串链表仅存首尾,数组元素个数为链表总数
string q[N]; //存储字符串末位
string p[N]; //存储字符串首位
int main(){
int n;
int temp=0;//空位置下标
cin>>n;
string a, b;
for(int i=0; i<n; i++){
cin>>a>>b;
int k=0;//插入位置下标
while(k<temp&&q[k]!=a) k++;//移动到正确的插入位置
q[k]=b;
if(k==temp){
p[temp]=a;
temp++;
}
}
cout<<temp<<endl;
for(int i=0; i<temp; i++) cout<<p[i]<<" "<<q[i]<<endl;
return 0;
}