#include <iostream> #include <sstream> using namespace std; int main() { istringstream sin; string s; while(getline(cin,s)) { sin.str(s); int a[1000]={0},b[1000]={0}; int i=0,j=0; while(sin >> a[i]) { bool bb=false; for(int p=0;p<i;p++) if(a[i]==a[p]) { bb=true; break; } if(bb==true) continue; i++; } for(int p=0;p<i;p++) { for(int q=p+1;q<i;q++) { if(a[p]>a[q]) a[p]^=a[q]^=a[p]^=a[q]; } } sin.clear(); getline(cin,s); sin.str(s); while(sin >> b[j]) { bool bb=false; for(int p=0;p<j;p++) if(b[j]==b[p]) { bb=true; break; } if(bb==true) continue; j++; } sin.clear(); for(int p=0;p<j;p++) { for(int q=p+1;q<j;q++) { if(b[p]>b[q]) b[p]^=b[q]^=b[p]^=b[q]; } } int m=0,n=0; int both=0; while(m<i&&n<j) { if(a[m]==b[n]) { m++;n++; both++; continue; } else if(a[m]<b[n]) m++; else n++; } if(both>0) { if(both==i&&both==j) { cout << "A equals B" << endl; continue; } else if(both==i&&both<j) { cout << "A is a proper subset of B" << endl; continue; } else if(both<i&&both==j) { cout << "B is a proper subset of A" << endl; continue; } else if(both<i&&both<j) { cout << "I'm confused!" << endl; continue; } } else if(both==0) { if(i>0&&j>0) { cout << "A and B are disjoint" << endl; continue; } else if(i==0&&j>0) { cout << "A is a proper subset of B" << endl; continue; } else if(j==0&&i>0) { cout << "B is a proper subset of A" << endl; continue; } else { cout << "A equals B" << endl; continue; } } } }
Sunday, August 24, 2014
uva - 496 - Simply Subsets
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment