不知道为啥错了
  • 板块P2814 家谱
  • 楼主jntm233
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/7/8 13:34
  • 上次更新2023/11/3 11:03:54
查看原帖
不知道为啥错了
835942
jntm233楼主2023/7/8 13:34
#include<iostream>
#include<string>
#include<map>
using namespace std;
map<string,string>pre;//俩string分别代表自己名字和祖先名字
char op;
string son,dad;
string find(string x){
	if(pre[x]==x)return pre[x];
	else pre[x]=find(pre[x]);
}
int main(){
	while(cin>>op){
		cin>>son;
		if(op=='$')break;
		else if(op=='#'){
			dad=son;
			if(pre[son]=="")pre[son]=son;
		}
		else if(op=='+'){
			pre[son]=dad;
		}
		else if(op=='?')cout<<son<<" "<<find(son)<<endl;
	}
}
2023/7/8 13:34
加载中...