全WA,求助大佬!!!
  • 板块P2814 家谱
  • 楼主wkzh
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/1/28 17:45
  • 上次更新2024/1/28 20:00:03
查看原帖
全WA,求助大佬!!!
769220
wkzh楼主2024/1/28 17:45
#include<bits/stdc++.h>
using namespace std;
map<string,string> fa;
string a;
string b;
string f(string x){
	if(fa[x]==x){
		return x;
	}
	return fa[x]=f(fa[x]);
}
void c(string x,string y){
	fa[y]=x;
}
int main(){
	while(cin>>a&&a!="$"){
		if(a[0]=='#'){
			a[0]='\0';
			if(fa[a]=="")
				fa[a]=a;
			b=a;
		}
		if(a[0]=='+'){
			a[0]='\0';
			fa[a]=a;
			c(b,a);
		}
		if(a[0]=='?'){
			a[0]='\0';
			cout<<a<<' '<<f(a)<<endl;
		}
	}
	return 0;
}
2024/1/28 17:45
加载中...