当前位置:网站首页>PAT1012

PAT1012

2022-08-09 11:09:00 AlanLiu6

我算是看明白了,pat无脑暴力就完事了
https://pintia.cn/problem-sets/994805342720868352/problems/994805502658068480

#include<cstdio>

int id[2005],c[2005],math[2005],english[2005],ave[2005];

// 纯暴力

int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i = 0;i < n;i++)
    {
        //int id,c,math,english;
        scanf("%d%d%d%d",&id[i],&c[i],&math[i],&english[i]);
        ave[i] = (c[i]+math[i]+english[i])/3;
    }
    for(int i = 0;i< m;i++)
    {
        int ID;
        int T = -1,C,M,E,A;
        int flag = 0;
        int AB=1,CB=1,MB=1,EB=1;
        scanf("%d",&ID);
        for(int j = 0;j < n;j++)
        {
            if(id[j] == ID)
            {
                flag++;
                C = c[j];
                M = math[j];
                E = english[j];
                A = ave[j];
                break;
            }
        }
        if(!flag)
        {
            printf("N/A\n");
            continue;
        }
        for(int j = 0;j < n;j++)
        {
            if(j == T) continue;
            if(c[j] > C) CB++;
            if(math[j] > M) MB++;
            if(english[j] > E) EB++;
            if(ave[j] > A) AB++;
        }
       // printf("A: %d\n",AB);
        if(AB <= CB && AB <= MB && AB <= EB) printf("%d A\n",AB);
        else if(CB < AB && CB <= MB && CB <= EB) printf("%d C\n",CB);
        else if(MB < CB && MB < AB && MB <= EB) printf("%d M\n",MB);
        else if(EB < CB && EB < MB && EB < AB) printf("%d E\n",EB);
    }


    return 0;
}

原网站

版权声明
本文为[AlanLiu6]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Alen666/article/details/98122351