Using set::set_intersect(params) the problem can be solved.
#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; }