Hello,world!

Fork me on CSDN

家谱

map是个好东西

 1 #include <iostream>
 2 #include <string>
 3 #include <map>
 4 using namespace std;
 5 map<string,string>p;
 6 
 7 string searchav(string x)
 8 {
 9     if(x!=p[x]) 
10         p[x]=searchav(p[x]);
11     return  p[x];
12 }
13 int main()
14 {
15     bool flag=false;
16     for(;;)
17     {
18         string x;
19         char char_f;
20         if(flag==false)
21         cin>>char_f;
22         if(char_f=='$')
23         {
24             break;
25         }
26         
27         if(char_f=='#')
28         {
29             
30             cin>>x;
31             
32             string father=x;
33             if(p[x]=="") p[x]=x;
34             for(;;)
35             {
36                 cin>>char_f;flag=true;
37                 if(char_f!='+')break;
38                 else
39                 {
40                     cin>>x;
41                     p[x]=father;
42                     flag=false;
43                 }
44             }
45         } 
46         if(char_f=='?')
47         {
48             cin>>x;
49             flag=false;    
50             cout<<x<<" "<<searchav(x)<<endl;
51         }
52     }
53     return 0;
54  }

 

posted @ 2019-03-17 21:08  CodingPLus  阅读(199)  评论(0编辑  收藏  举报



Free website hit counter

Night,city.