UVA Problem 496 ( Simply Subsets )Solution

Problem Solving, UVa

 

#include <iostream>

#include <string>

#include <sstream>

#include <vector>



using namespace std;



int main()

{

   

    stringstream ss;

   

    string line1,line2;

   

    vector<int>A,B;

   

    int i,j,ch;

   

    while(getline(cin,line1) &&    getline(cin,line2))

    {

   

    A.clear();

    B.clear();

    ss.clear();

    ss<<line1;   

   

    while(ss>>ch)

    {

        A.push_back(ch);

    }

   



    ss.clear();

    ss<<line2;   

    while(ss>>ch)

    {

        B.push_back(ch);

    }   

   

    int Acnt=0;

    for(int m=0;m<A.size();m++)

    {

        for(int n=0;n<B.size();n++)

        {

            if(A[m]==B[n])

            {

                Acnt++;

       

            }

        }

    }

           

         if ((Acnt == A.size()) && (Acnt < B.size())) {

            cout << "A is a proper subset of B" << endl;

        }

        else if ((Acnt == B.size()) && (Acnt < A.size())) {

            cout << "B is a proper subset of A" << endl;

        }

        else if ((Acnt == A.size()) && (Acnt == B.size())) {

            cout << "A equals B" << endl;

        }

        else if ((Acnt == 0) ) {

            cout << "A and B are disjoint" << endl;

        }

        else {

            cout << "I'm confused!" << endl;   

        }

    }

   

    return 0;

}



 

0 Comments

You may find interest following article