forked from zjpzhao/JLU_data_structure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4-3set.cpp
More file actions
54 lines (53 loc) · 811 Bytes
/
4-3set.cpp
File metadata and controls
54 lines (53 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
using namespace std;
int father[300];
int fa(int t)
{
if(father[t]==t)
return t;
return father[t]=fa(father[t]);
}
int main()
{
for(int i=0;i<=256;i++)
father[i]=i;
char t1,t2;
while(cin>>t1)
{
if(t1=='|')
break;
while(cin>>t2)
{
if(t2=='|')
break;
father[fa(t1)]=fa(t2);
}
}
cout<<"集合创建完毕"<<endl;
string s;
while(cin>>s)
{
if(s=="union")
{
cin>>t1>>t2;
father[fa(t1)]=fa(t2);
}
if(s=="search")
{
cin>>t1>>t2;
if(fa(t1)==fa(t2))
cout<<"true"<<endl;
else
cout<<"false"<<endl;
}
if(s=="quit")
break;
if(s=="show")
{
for(int i='a';i<='n';i++)
cout<<father[i]<<" ";
cout<<endl;
}
}
return 0;
}