- A is a proper subset of B (A 是 B 的子集合)
- B is a proper subset of A (B 是 A 的子集合)
- A equals B (A、B 是相同集合)
- A and B are disjoint (A、B 完全沒有交集)
- I'm confused! (A、B 有部分交集)
55 27 55 27 9 24 1995 9 24 1 2 3 1 2 3 4 1 2 3 4 5 6 1 2 2 3
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!
C++:
/*
A is a proper subset of B (A 是 B 的子集合)
B is a proper subset of A (B 是 A 的子集合)
A equals B (A、B 是相同集合)
A and B are disjoint (A、B 完全沒有交集)
I'm confused! (A、B 有部分交集)
解題思路:
把A B兩個set放完後,再做第三個set,裡面放A B 共同永有的元素
*/
#include <iostream>
#include <sstream>
#include <set>
using namespace std;
int main(){
string s;
while(getline(cin,s)){
set <string> A,B,common;
stringstream ss(s);
while(ss>>s){
A.insert(s);
}
getline(cin,s);
ss.clear();
ss.str(s);
while(ss>>s){
B.insert(s);
}
//輸入完成
set <string>::iterator i;
for(i=A.begin();i!=A.end();i++){
if(B.count(*i)){
common.insert(*i);
B.erase(*i);
}
}
for(i=common.begin();i!=common.end();i++){
A.erase(*i);
}
/*輸出檢查 cout<<<<"\n";
for(i=common.begin();i!=common.end();i++){
cout<<*i<<"\n";
}*/
if(A.empty() && B.empty()){
cout<<"A equals B\n";
}
else if(A.empty() && !B.empty()){
cout<<"A is a proper subset of B\n";
}
else if(B.empty() && !A.empty() ){
cout<<"B is a proper subset of A\n";
}
else if(!A.empty() && !B.empty() && common.empty()){
cout<<"A and B are disjoint\n";
}
else{
cout<<"I'm confused!\n";
}
}
return 0;
}
:python:
# 測試過了 # 但隱藏測資沒過 # 還期望大神多幫忙 """ A is a proper subset of B (A 是 B 的子集合) B is a proper subset of A (B 是 A 的子集合) A equals B (A、B 是相同集合) A and B are disjoint (A、B 完全沒有交集) I'm confused! (A、B 有部分交集) """ while True: try: A=list(map(int,input().split())) B=list(map(int,input().split())) common=[] for i in A: if i in B: common.append(i) B.remove(i) for i in common: A.remove(i) """ print(A) print(B) print(common) """ if len(A)==0 and len(B)==0 and len(common)!=0:print("A equals B ") elif len(A)!=0 and len(B)==0 and len(common)!=0:print("B is a proper subset of A") elif len(A)==0 and len(B)!=0 and len(common)!=0:print("A is a proper subset of B") elif len(A)!=0 and len(B)!=0 and len(common)==0:print("A and B are disjoint") else:print("I'm confused!") except:break
留言列表