社区讨论
输出错误求调,闭关
P2814家谱参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mko4nu9t
- 此快照首次捕获于
- 2026/01/21 22:37 2 个月前
- 此快照最后确认于
- 2026/01/22 18:08 2 个月前
CPP
#include<iostream>
#include<map>
#include<string>
using namespace std;
map<string,string> f;
string find(string n){
if(n!=f[n]){
f[n]=find(f[n]);
}
return f[n];
}
int main(){
while(true){
char c;
string s,a;
cin>>c;
if(c=='$'){
return 0;
}
cin>>s;
if(c=='#'){
a=s;
if(f[s]==""){
f[s]=s;
}
}else if(c=='+'){
f[s]=a;
}else if(c=='?'){
cout<<s<<" "<<find(s)<<endl;
}
}
return 0;
}
样例输出了
CPPEdward
Walter
Rodney
Arthur Arthur
回复
共 0 条回复,欢迎继续交流。
正在加载回复...