【无标题】

结构之善于总结

(错误终于纠正版)

qsort函数,多级排序

Description

最近acm队决定对近期举行的n场比赛做一总结,以研究哪几场比赛题目难度分配正常,但苦于任务艰巨没人想做,所以就找上你啦~~~ 

Input

 第一行为一个正整数n(0<n<100),接下来有n行。对于每一行有9个整数,第一个整数为比赛序号,接下来八个代表第1~8题的成功解题人数。 

Output

输出难度分配最简单的比赛的序号。若题号越小的题目解出的人数越多,则该比赛越简单。(当然和现实的acm赛有区别) 

Samples

input Copy

5

1 200 300 400 500 600 700 800 900

2 900 900 800 700 600 400 200 100

3 900 800 700 600 500 400 300 200

4 800 800 800 800 800 800 800 800

5 1 2 3 4 5 6 7 8

output Copy

2

Hint

1. 以样例为例

先看第一题,做出来最多的是2、3号比赛

继续看第二题,2号做出来的比3号多

所以答案是2号

2. 序号不一定是连续的,可以是任何int类型的整数。

#include<stdio.h>
#include<stdlib.h>
struct stu {
    int number;
    int score[9];
};
int cmp(const void* a, const void* b) {
    int i=0;
    while((*(struct stu*)a).score[i] == (*(struct stu*)b).score[i]){
        i++;
    }
    return (*(struct stu*)b).score[i] - (*(struct stu*)a).score[i];
   /* if ((*(struct stu*)a).score[0] != (*(struct stu*)b).score[0]) {
        return (*(struct stu*)b).score[0] - (*(struct stu*)a).score[0];
    }else if ((*(struct stu*)a).score[1] != (*(struct stu*)b).score[1]) {
        return (*(struct stu*)b).score[1] - (*(struct stu*)a).score[1];
    }
    else if ((*(struct stu*)a).score[2] != (*(struct stu*)b).score[2]) {
        return (*(struct stu*)b).score[2] - (*(struct stu*)a).score[2];
    }
    else if ((*(struct stu*)a).score[3] != (*(struct stu*)b).score[3]) {
        return (*(struct stu*)b).score[3] - (*(struct stu*)a).score[3];
    }
    else if ((*(struct stu*)a).score[4] != (*(struct stu*)b).score[4]) {
        return (*(struct stu*)b).score[4] - (*(struct stu*)a).score[4];
    }
    else if ((*(struct stu*)a).score[5] != (*(struct stu*)b).score[5]) {
        return (*(struct stu*)b).score[5] - (*(struct stu*)a).score[5];
    }
    else if ((*(struct stu*)a).score[6] != (*(struct stu*)b).score[6]) {
        return (*(struct stu*)b).score[6] - (*(struct stu*)a).score[6];
    }
    else
        return (*(struct stu*)b).score[7] - (*(struct stu*)a).score[7];*/
}
int main() {
    int n,i,j;
    struct stu team[101];
    scanf("%d", &n);
    int t=n;
    i = j = 0;
    while (n--) {
        scanf("%d", &team[j].number);
        for (i = 0; i < 8; i++) {
            scanf("%d", &team[j].score[i]);
        }
        j++;
    }
    qsort(team, t, sizeof(team[0]), cmp);
    printf("%d\n", team[0].number);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值