POJ 2062 HDU 1528 ZOJ 2223 Card Game Cheater

水题,感觉和田忌赛马差不多

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;



struct P1

{

    int Num;

    int Hua;

} Play1[30];



struct P2

{

    int Num;

    int Hua;

} Play2[30];



bool cmp1(const P1&a,const P1&b)

{

    if(a.Num==b.Num) return a.Hua<b.Hua;

    return a.Num<b.Num;

}

bool cmp2(const P2&a,const P2&b)

{

    if(a.Num==b.Num) return a.Hua<b.Hua;

    return a.Num<b.Num;

}



int main()

{

    int n;

    int i,j;

    char s[5];

    int TT;

    scanf("%d",&TT);

    while(TT--)

    {

        scanf("%d",&n);

        for(i=0; i<n; i++)

        {

            scanf("%s",s);

            int num,hua;

            if(s[0]>='0'&&s[0]<='9') num=s[0]-'0';

            if(s[0]=='T') num=10;

            if(s[0]=='J') num=11;

            if(s[0]=='Q') num=12;

            if(s[0]=='K') num=13;

            if(s[0]=='A') num=14;

            Play1[i].Num=num;

            if(s[1]=='C') hua=1;

            if(s[1]=='D') hua=2;

            if(s[1]=='S') hua=3;

            if(s[1]=='H') hua=4;

            Play1[i].Hua=hua;

        }

        sort(Play1,Play1+n,cmp1);

        for(i=0; i<n; i++)

        {

            scanf("%s",s);

            int num,hua;

            if(s[0]>='0'&&s[0]<='9') num=s[0]-'0';

            if(s[0]=='T') num=10;

            if(s[0]=='J') num=11;

            if(s[0]=='Q') num=12;

            if(s[0]=='K') num=13;

            if(s[0]=='A') num=14;

            Play2[i].Num=num;

            if(s[1]=='C') hua=1;

            if(s[1]=='D') hua=2;

            if(s[1]=='S') hua=3;

            if(s[1]=='H') hua=4;

            Play2[i].Hua=hua;

        }

        sort(Play2,Play2+n,cmp2);

        int ans=0;

        int P=0;

        for(i=0; i<n; i++)

        {

            for(j=P; j<n; j++)

            {

                if((Play2[j].Num>Play1[i].Num)||(Play2[j].Num==Play1[i].Num&&Play2[j].Hua>Play1[i].Hua))

                {

                    ans++;

                    

                    P=j+1;break;

                }

            }

        }

        printf("%d\n",ans);

    }

    return 0;

}

 

你可能感兴趣的:(game)