记录详情

Wrong Answer

/in/foo.c: In function 'main':
/in/foo.c:69:49: warning: passing argument 4 of 'qsort' from incompatible pointer type [-Wincompatible-pointer-types]
             qsort(player[i].point,3,sizeof(int),cmpP);
                                                 ^~~~
In file included from /in/foo.c:2:0:
/usr/include/stdlib.h:725:13: note: expected '__compar_fn_t {aka int (*)(const void *, const void *)}' but argument is of type 'int (*)(void *, void *)'
 extern void qsort (void *__base, size_t __nmemb, size_t __size,
             ^~~~~
/in/foo.c:78:39: warning: passing argument 4 of 'qsort' from incompatible pointer type [-Wincompatible-pointer-types]
         qsort(player,n,sizeof(PLAYER),cmpW);
                                       ^~~~
In file included from /in/foo.c:2:0:
/usr/include/stdlib.h:725:13: note: expected '__compar_fn_t {aka int (*)(const void *, const void *)}' but argument is of type 'int (*)(void *, void *)'
 extern void qsort (void *__base, size_t __nmemb, size_t __size,
             ^~~~~
# 状态 耗时 内存占用
#1 Wrong Answer 1ms 228.0 KiB
#2 Wrong Answer 1ms 128.0 KiB
#3 Wrong Answer 1ms 220.0 KiB
#4 Wrong Answer 1ms 228.0 KiB

代码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct
{
    char name[11];
    char suit[3];
    int point[3];
    int weight;
    int mpoint;
}PLAYER;

int IsSuit(PLAYER pl);
int IsFlush(PLAYER pl);
int IsFS(PLAYER pl);
int IsHouse(PLAYER pl);
int Find(PLAYER pl);

int cmpP(void* a,void* b)
{
    return *(int*)a-*(int*)b;
}

int cmpW(void* a,void* b)
{
    PLAYER* p1=(PLAYER*)a;
    PLAYER* p2=(PLAYER*)b;
    if(p1->weight!=p2->weight)
        return p1->weight-p2->weight;
    else if(p1->mpoint!=p2->mpoint)
        return p1->mpoint-p2->mpoint;
    else return strcmp(p1->name,p2->name);

}

int main(void)
{
    int T;
    scanf("%d",&T);
    int n;
    int t,i,j;
    for(t=0;t<T;t++)
    {
        scanf("%d",&n);
        PLAYER player[100];
        char ch;
        for(i=0;i<n;i++)
        {
            scanf("%s",player[i].name);
            for(j=0;j<3;j++)
            {
                scanf(" %c",&player[i].suit[j]);
                scanf(" %c",&ch);
                if(ch>='2'&&ch<='9')
                    player[i].point[j]=ch-'0';
                else
                {
                    switch(ch)
                    {
                    case '1':player[i].point[j]=10;break;
                    case 'J':player[i].point[j]=11;break;
                    case 'Q':player[i].point[j]=12;break;
                    case 'K':player[i].point[j]=13;break;
                    case 'A':player[i].point[j]=14;break;
                    }
                }
            }
            qsort(player[i].point,3,sizeof(int),cmpP);
            player[i].weight=IsHouse(player[i]);
            if(player[i].weight!=6)
                player[i].weight=IsFS(player[i]);
            if(player[i].weight!=2)
                player[i].mpoint=10000*player[i].point[2]+100*player[i].point[1]+player[i].point[0];
            else
                player[i].mpoint=Find(player[i]);
        }
        qsort(player,n,sizeof(PLAYER),cmpW);
        for(i=n-1;i>=0;i--)
            printf("%s\n",player[i].name);
    }
}

int Find(PLAYER pl)
{
    if(pl.point[0]==pl.point[1])
        return 100*pl.point[0]+pl.point[2];
    else if(pl.point[0]==pl.point[2])
        return 100*pl.point[0]+pl.point[1];
    else return 100*pl.point[1]+pl.point[0];
}

int IsHouse(PLAYER pl)
{
    if(pl.point[0]==pl.point[1]&&pl.point[0]==pl.point[2])
        return 6;
    else if(pl.point[0]==pl.point[1]||pl.point[0]==pl.point[2]||pl.point[1]==pl.point[2])
        return 2;
    else return 1;
}

int IsFS(PLAYER pl)
{
    int ff=IsFlush(pl);
    int ss=IsSuit(pl);
    if(ff&ss)
        return 5;
    else if(ss)
        return 4;
    else if(ff)
        return 3;
    else return pl.weight;
}

int IsFlush(PLAYER pl)
{
    if(pl.point[0]==pl.point[1]-1&&pl.point[1]==pl.point[2]-1)
        return 1;
    else return 0;
}

int IsSuit(PLAYER pl)
{
    if(pl.suit[0]==pl.suit[1]&&pl.suit[0]==pl.suit[2])
        return 1;
    else return 0;
}

信息

递交者
类型
递交
题目
P1004 hitwh 2019 新生赛 E EdChu 与炸金花
语言
C
递交时间
2020-12-20 09:34:15
评测时间
2020-12-20 09:34:15
评测机
分数
0
总耗时
5ms
峰值内存
228.0 KiB