Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴一份WA的代码,求大神指导,知道的请邮件,多谢了!!!

Posted by 2012xie at 2013-02-05 20:21:40 on Problem 1786
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct pai
{
    int hua;
    int num;
}p[4][13];
int i,j,k,flag,tmp,player,n_pai;
char c,s[30];
int cmp(const void*a,const void*b)
{
    pai *p1=(pai*)a;
    pai *p2=(pai*)b;
    if(p1->hua!=p2->hua)
        return p1->hua-p2->hua;
    else
        return p1->num-p2->num;
}
void input()
{
        switch(c)
        {
        case('N'):
            {
                flag=1;
                break;
            }
        case('E'):
            {
                flag=2;
                break;
            }
        case('S'):
            {
                flag=3;
                break;
            }
        case('W'):
            {
                flag=4;
                break;
            }
        }
        scanf("%s",s);
        player=n_pai=0;
        for(i=0;s[i];i+=2)
        {
            switch(s[i])
            {
            case('H'):
                {
                    tmp=4;
                    break;
                }
            case('S'):
                {
                    tmp=3;
                    break;
                }
            case('D'):
                {
                    tmp=2;
                    break;
                }
            case('C'):
                {
                    tmp=1;
                    break;
                }
            }
            p[player][n_pai].hua=tmp;
            if('2'<=s[i+1]&&s[i+1]<='9')
                tmp=s[i+1]-'0'-1;
            else if(s[i+1]=='T')
                tmp=9;
            else if(s[i+1]=='J')
                tmp=10;
            else if(s[i+1]=='Q')
                tmp=11;
            else if(s[i+1]=='K')
                tmp=12;
            else if(s[i+1]=='A')
                tmp=13;
            p[player][n_pai].num=tmp;
            player++;
            player=player%4;
            if(player==0)
                n_pai++;
        }
        scanf("%s",s);
        for(i=0;s[i];i+=2)
        {
            switch(s[i])
            {
            case('H'):
                {
                    tmp=4;
                    break;
                }
            case('S'):
                {
                    tmp=3;
                    break;
                }
            case('D'):
                {
                    tmp=2;
                    break;
                }
            case('C'):
                {
                    tmp=1;
                    break;
                }
            }
            p[player][n_pai].hua=tmp;
            if('2'<=s[i+1]&&s[i+1]<='9')
                tmp=s[i+1]-'0'-1;
            else if(s[i+1]=='T')
                tmp=9;
            else if(s[i+1]=='J')
                tmp=10;
            else if(s[i+1]=='Q')
                tmp=11;
            else if(s[i+1]=='K')
                tmp=12;
            else if(s[i+1]=='A')
                tmp=13;
            p[player][n_pai].num=tmp;
            player++;
            player=player%4;
            if(player==0)
                n_pai++;
        }
}
char get_num(int x)
{
    if(x>=1&&x<=8)
        return x+'0'+1;
    else if(x==9)
        return 'T';
    else if(x==10)
        return 'J';
    else if(x==11)
        return 'Q';
    else if(x==12)
        return 'K';
    else if(x==13)
        return 'A';
}
char get_hua(int x)
{
    if(x==1)
        return 'C';
    else if(x==2)
        return 'D';
    else if(x==3)
        return 'S';
    else if(x==4)
        return 'H';
}
void output(pai*p_n)
{
    for(i=0;i<13;i++)
        printf("+---");
    printf("+\n");
    for(i=0;i<13;i++)
        printf("|%c %c",get_num(p_n[i].num),get_num(p_n[i].num));
    printf("|\n");
    for(i=0;i<13;i++)
        printf("| %c ",get_hua(p_n[i].hua));
    printf("|\n");
    for(i=0;i<13;i++)
        printf("|%c %c",get_num(p_n[i].num),get_num(p_n[i].num));
    printf("|\n");
    for(i=0;i<13;i++)
        printf("+---");
    printf("+\n");
}
int main()
{
    freopen("input.txt","r",stdin);
    /*int i,j,count;
    for(count=0;count<13;count++)
    {
        scanf("%d%d",&p[0][count].hua,&p[0][count].num);
    }
    qsort(p[0],13,sizeof(p[0][0]),cmp);
    for(i=0;i<13;i++)
        printf("%d %d\n",p[0][i].hua,p[0][i].num);*/
    while(1)
    {
        scanf("%c",&c);
        if(c=='#')break;
        input();
        getchar();
        //printf("%d\n",flag);
        /*for(i=0;i<4;i++)
        {
            for(j=0;j<13;j++)
                printf("%d%d ",p[i][j].hua,p[i][j].num);
            printf("\n");
        }*/
        for(i=0;i<4;i++)
            qsort(p[i],13,sizeof(p[0][0]),cmp);
        switch(flag)
        {
        case(1):
            {
                printf("South player:\n");
                output(p[1]);
                printf("West player:\n");
                output(p[2]);
                printf("North player:\n");
                output(p[3]);
                printf("East player:\n");
                output(p[0]);
                break;
            }
        case(2):
            {
                printf("South player:\n");
                output(p[0]);
                printf("West player:\n");
                output(p[1]);
                printf("North player:\n");
                output(p[2]);
                printf("East player:\n");
                output(p[3]);
                break;
            }
        case(3):
            {
                printf("South player:\n");
                output(p[3]);
                printf("West player:\n");
                output(p[0]);
                printf("North player:\n");
                output(p[1]);
                printf("East player:\n");
                output(p[2]);
                break;
            }
        case(4):
            {
                printf("South player:\n");
                output(p[2]);
                printf("West player:\n");
                output(p[3]);
                printf("North player:\n");
                output(p[0]);
                printf("East player:\n");
                output(p[1]);
                break;
            }
        }
        printf("\n");
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator