30分求解
查看原帖
30分求解
1020629
The_Leaf_of_Wind楼主2023/9/23 17:08
#include<bits/stdc++.h>
using namespace std;
map<string,string>fa;
const int N=50005;
int h;
string b,tem,a[N];
string f(string x){
	if(fa[x]==x) return x;
	else return fa[x]=f(fa[x]);
}
int main(){
	for(int i=1;cin>>tem;i++){
		char ccf=tem[0];
		tem.erase(0,1);
		if(ccf=='$') return 0;
		if(ccf=='#'&&fa.find(tem)==fa.end()){
			fa[tem]=tem;
			b=tem;
		}
		else if(ccf=='#'){
			b=tem;
		}
		if(ccf=='+'){
			string t1=f(b);
			string t2=f(tem);
			fa[t2]=t1;
		}
		if(ccf=='?'){
			cout<<tem<<" "<<f(tem)<<endl;
		}
	}
	return 0;
}

30分记录

2023/9/23 17:08
加载中...