Uva 496 - Simply Subsets


 #include<iostream>
#include<cstdio>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<cstring>
#include<string>
#include<sstream>

#define pf printf
#define sf scanf
#define nl puts("")

using namespace std;

typedef long long LL;

int main()
{
    string s;
    set<LL>ek;
    set<LL>::iterator itek;
    set<LL>dui;
    set<LL>::iterator itdui;
    LL cnvrt,i,j,eklen,duilen,cnt;
    while(getline(cin,s))
    {
        stringstream ss1(s);
        while(ss1 >> cnvrt)
        {
            ek.insert(cnvrt);
        }

        eklen=ek.size();

        s.clear();

        getline(cin,s);
        stringstream ss2(s);
        while(ss2 >> cnvrt)
        {
            dui.insert(cnvrt);
        }

        duilen=dui.size(); cnt=0;

        //for(itek=ek.begin();itek!=ek.end();itek++)cout << *itek << " "; nl;
        //for(itdui=dui.begin();itdui!=dui.end();itdui++)cout << *itdui << " ";
        //cout << eklen << " " << duilen;

        if(eklen>duilen)
        {
            for(itek=ek.begin();itek!=ek.end();itek++)
            {
                for(itdui=dui.begin();itdui!=dui.end();itdui++)
                {
                    if(*itek == *itdui)
                    {
                        cnt++;
                    }
                }
            }

            if(cnt==duilen)
            {
                pf("B is a proper subset of A\n");
            }

            else if(cnt==0)
            {
                pf("A and B are disjoint\n");
            }

            else
            {
                pf("I'm confused!\n");
            }

            cnt=0;
        }

        else if(eklen<duilen)
        {
            for(itdui=dui.begin();itdui!=dui.end();itdui++)
            {
                for(itek=ek.begin();itek!=ek.end();itek++)
                {
                    if(*itek == *itdui)
                    {
                        cnt++;
                    }
                }
            }

            if(cnt==eklen)
            {
                pf("A is a proper subset of B\n");
            }

            else if(cnt==0)
            {
                pf("A and B are disjoint\n");
            }

            else
            {
                pf("I'm confused\n");
            }

            cnt=0;
        }

        else if(eklen==duilen)
        {
            for(itek=ek.begin();itek!=ek.end();itek++)
            {
                for(itdui=dui.begin();itdui!=dui.end();itdui++)
                {
                    if(*itek == *itdui)
                    {
                        cnt++;
                    }
                }
            }

            if(cnt==eklen and cnt==duilen)
            {
                pf("A equals B\n");
            }

            else if(cnt==eklen and cnt!=duilen)
            {
                pf("A is a proper subset of B\n");
            }

            else if(cnt!=eklen and cnt==duilen)
            {
                pf("B is a proper subset of A\n");
            }

            else if(cnt==0)
            {
                pf("A and B are disjoint\n");
            }

            else
            {
                pf("I'm confused!\n");
            }
        }

        else
        {
            pf("I'm confused!\n");
        }

        ek.clear();
        dui.clear();
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number