Description
给定两个集合A、B,集合内的任一元素x满足1 ≤ x ≤ 109,并且每个集合的元素个数不大于105。我们希望求出A、B之间的关系。
任 务 :给定两个集合的描述,判断它们满足下列关系的哪一种:
A是B的一个真子集,输出“A is a proper subset of B”
B是A的一个真子集,输出“B is a proper subset of A”
A和B是同一个集合,输出“A equals B”
A和B的交集为空,输出“A and B are disjoint”
上述情况都不是,输出“I'm confused!”
Input
输入有两行,分别表示两个集合,每行的第一个整数为这个集合的元素个数(至少一个),然后紧跟着这个集合的元素(均为不同的正整数)
Output
输出只有一行,就是A、B的关系。
Sample Input
2 55 27 2 55 27 3 9 24 19 2 9 24 3 1 2 3 4 1 2 3 4 3 1 2 3 3 4 5 6 2 1 2 2 2 3
Sample Output
A equals B B is a proper subset of A A is a proper subset of B A and B are disjoint I'm confused!
Source:#include < iostream >
using namespace std;
int la;
int lb;
int a[ 120 ];
int b[ 120 ];
void input()
... {
cin>>la;
for(int i=1;i<=la;i++)
...{
cin>>a[i];
}
cin>>lb;
for(int j=1;j<=lb;j++)
...{
cin>>b[j];
}
}
void sort_a()
... {
int i,j;
int t;
for(i=1;i<=la;i++)
for(j=1;j<=la;j++)
...{
if(a[i]<a[j])
...{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
void sort_b()
... {
int i,j;
int t;
for(i=1;i<=lb;i++)
for(j=1;j<=lb;j++)
...{
if(b[i]<b[j])
...{
t=b[i];
b[i]=b[j];
b[j]=t;
}
}
}
int compare1()
... {
int j;
for(int i=1;i<=la;i++)
...{
for(j=1;j<=lb;j++)
...{
if(a[i]==b[j]) break;
}
if(j>lb) return 0;
}
return 1;
}
int compare2()
... {
int j;
for(int i=1;i<=lb;i++)
...{
for(j=1;j<=la;j++)
...{
if(a[i]==b[j]) break;
}
if(i>la) return 0;
}
return 1;
}
int compare3()
... {
if(compare1()&&compare2()) return 1;
else return 0;
}
int compare4()
... {
for(int i=1;i<=lb;i++)
...{
for(int j=1;j<=la;j++)
...{
if(a[i]==b[j]) return 0;
}
}
return 1;
}
void output()
... {
if(la<lb&&compare1())
...{
cout<<"A is a proper subset of B"<<endl;
exit(1);
}
if(la>lb&&compare2())
...{
cout<<"B is a proper subset of A"<<endl;
exit(1);
}
if(la==lb&&compare3())
...{
cout<<"A equals B"<<endl;
exit(1);
}
if(compare4())
...{
cout<<"A and B are disjoint"<<endl;
exit(1);
}
cout<<"I'm confused!"<<endl;
}
int main()
... {
//freopen("1980.txt","r",stdin);
input();
//sort_a();
//sort_b();
output();
}