2021HBUTeduCN 2021-10-10 15:31 采纳率: 100%
浏览 50
已结题

pta 乙级1032的第三个测试点是啥啊?

自己写的还有网上复制跑通的代码去测试结果全是第三个测试点出问题
这是我的代码,不知道哪出问题了,希望有人指点下

#include<stdio.h>
#define maxsize 100005
struct data
{
    int num;
   int score;
}max;
int main()
{
    int n;
    data teams[maxsize]={};
    max = {0,0};
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        teams[a].num = a;
        teams[a].score += b;
    }
    for(int k=1;k<n+1;k++)
    {
        if(teams[k].score>max.score)
        {
            max = teams[k];
        }
    }
    printf("%d %d",max.num,max.score);
}


  • 写回答

1条回答 默认 最新

  • 关注

    修改后如下:

    #include <stdio.h>
    #define maxsize 100005
    struct data
    {
        int num;
        int score;
    } max;
    int main()
    {
        int n;
        struct data teams[maxsize] = {};
        max.num = 0;
        max.score = 0;
        scanf("%d", &n);
        for (int i = 0; i < n; i++)
        {
            int a, b;
            scanf("%d %d", &a, &b);
            teams[i].num = a;
            teams[i].score = b;
        }
        for (int k = 1; k < n + 1; k++)
        {
            if (teams[k].score > max.score)
            {
                max = teams[k];
            }
           
        }
        printf("%d %d", max.num, max.score);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月18日
  • 已采纳回答 10月10日
  • 创建了问题 10月10日