1 solutions
-
0
C++ :
#include<map> #include<iostream> using namespace std; map<string,string> father; string getfather(string x) { if(father[x]!=x) { return getfather(father[x]); } else { return father[x]; } } int main() { char c; string s,fat; cin>>c; while(c!='$') { cin>>s; if(c=='#') { fat=s; if(father[s]=="") father[s]=s; } if(c=='+') { father[s]=fat; } if(c=='?') { cout<<s<<' '<<getfather(father[s])<<endl; } cin>>c; } return 0; }
- 1
Information
- ID
- 10274
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By