码迷,mamicode.com
首页 > 其他好文 > 详细

PAT B1042 挖掘机哪家强

时间:2019-07-29 17:42:20      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:int   编号   最大   pac   初始   pre   color   代码   成绩   

AC代码

#include <cstdio>
#include <algorithm>

using namespace std;

const int max_n = 110000; //题目让给不超过10^5的正整数

struct School {
    int score;
} school[max_n];

void init() {   //初始化各个学校成绩
    for(int i = 0; i < max_n; i++) {
        school[i].score = 0;
    }
}

int main() {
    void();
    #ifdef ONLINE_JUDGE
    #else
        freopen("1.txt", "r", stdin);
    #endif // ONLINE_JUDGE
    int n = 0, biggest = 0; //n为参赛人数, biggest为参赛最大学校编号
    int MAX_num = -1, MAX = -1; //a为总得分最高的编号, b为总得分最高的总分
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        int no = 0, score = 0;
        scanf("%d%d", &no, &score);
        school[no].score += score;
        //int da = max(no, biggest);
        //biggest = da;
    }

    for (int i = 0; i < max_n; i++) {
        /*if(school[i].score != 0) {
                printf("schID:%d schScore:%d\n", i, school[i].score);
        }
        */
        if(school[i].score != 0) {
            if(school[i].score >  MAX) {
                MAX = school[i].score;
                MAX_num = i;
            }
        }
    }

    printf("%d %d", MAX_num, MAX);
    return 0;
}

PAT B1042 挖掘机哪家强

标签:int   编号   最大   pac   初始   pre   color   代码   成绩   

原文地址:https://www.cnblogs.com/isChenJY/p/11265210.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!