Using set::set_intersect(params) the problem can be solved.
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 |
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <set> #include <algorithm> #include <sstream> #define INF 1000000 using namespace std; set<int> Set1,Set2,inn; int main() { int n; string str; stringstream ss; while(getline(cin,str)) { Set1.clear(); Set2.clear(); inn.clear(); ss.clear(); ss<<str; while(ss>>n) { Set1.insert(n); } getline(cin,str); ss.clear(); ss<<str; while(ss>>n) { Set2.insert(n); } set_intersection(Set1.begin(),Set1.end(),Set2.begin(),Set2.end(),insert_iterator< set<int> >(inn,inn.begin())); if(Set1==Set2) cout<<"A equals B\n"; else if(Set2==inn) cout<<"B is a proper subset of A\n"; else if(Set1==inn) cout<<"A is a proper subset of B\n"; else if(inn.size()==0) cout<<"A and B are disjoint\n"; else cout<<"I'm confused!\n"; } return 0; } |