Uva 11678 - Cards' Exchange


 // Accepted

#include<iostream>
#include<cstdio>
#include<set>
#include<cstring>

#define N 100100
#define sf scanf
#define pf printf

using namespace std;

typedef long long LL;

bool flag[N+9];

int main()
{
    LL A,B,i,x,alicesz,bettysz;
    set<LL>alice;
    set<LL>::iterator italice;
    set<LL>betty;
    set<LL>::iterator itbetty;

    while(~sf("%lld %lld",&A,&B))
    {
        if(A == 0 and B == 0) break;

        alice.clear();
        betty.clear();
        memset(flag,false,sizeof(flag));

        for(i=0;i<A;i++)
        {
            sf("%lld",&x);
            alice.insert(x);
        }

        alicesz = alice.size();

        for(italice=alice.begin();italice!=alice.end();italice++)
        {
            flag[*italice]=true;
        }

        for(i=0;i<B;i++)
        {
            sf("%lld",&x);
            betty.insert(x);
        }

        bettysz = betty.size();

        for(itbetty=betty.begin();itbetty!=betty.end();itbetty++)
        {
            if(flag[*itbetty])
            {
                alicesz--;
                bettysz--;
            }
        }

        if(alicesz > bettysz)
        {
            pf("%lld\n",bettysz);
        }

        else if(alicesz < bettysz)
        {
            pf("%lld\n",alicesz);
        }

        else
        {
            pf("%lld\n",alicesz);
        }
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number