一.问题:

为了用事实说明挖掘机技术到底哪家强,PAT 组织了一场挖掘机技能大赛。现请你根据比赛结果统计出技术最强的那个学校。

输入格式:

输入在第 1 行给出不超过 105 的正整数 N,即参赛人数。随后 N 行,每行给出一位参赛者的信息和成绩,包括其所代表的学校的编号(从 1 开始连续编号)、及其比赛成绩(百分制),中间以空格分隔。

输出格式:

在一行中给出总得分最高的学校的编号、及其总分,中间以空格分隔。题目保证答案唯一,没有并列。

输入样例:

6
3 65
2 80
1 100
2 70
3 40
3 0

输出样例:

2 150

二.思路:

        具体看代码,这一题告诉我们搞一个副本有时候很有用

三.代码实现(C语言描述):

#include<stdio.h>
typedef struct person
{
    int school;
    int grades ;
}People;

//快速排序,从大到小排序数据
void quick_sort(int *School,int low,int high)
{
    int i = low;
    int j = high;
    int base = low;
    int temp = School[low];
    
    int t = 0;
    if(i > j)
    {
        return;
    }
    while(i < j)
    {
        while(School[j] <= temp &&i < j)
        {
            j--;
        }
        while(School[i] >= temp &&i < j)
        {
            i++;
        }
        t = School[i];
        School[i] = School[j];
        School[j] = t;
    }
    School[base] = School[i];
    School[i] = temp;

    

    //递归
    quick_sort(School,low,i-1);
    quick_sort(School,i+1,high);
}
int main()
{
    //输入数据
    int N = 0;
    scanf("%d",&N);
    int School[N] = {0};
    int cpy_School[N] = {0};
    People people[N];
    for(int i =0;i < N;i++)
    {
        scanf("%d %d",&people[i].school,&people[i].grades);
    }
    //整理数据
    int sum = 0;
    for(int i =0,p=0;i < N;i++)
    {
        p = (people[i].school)-1;
        School[p] += people[i].grades;
        cpy_School[p] += people[i].grades;
        sum = sum < (p+1) ?(p+1):sum;
        
        
    }
    //从大到小排序数据
    quick_sort(School,0,sum-1);
    for(int i =0;i < sum;i++)
    {
        if(School[0] == cpy_School[i])
        {
            //输出数据
            printf("%d %d\n",i+1,School[0]);
        }
    }
    return 0;
}
   
10-16 05:31