萌新求助

P1093 [NOIP2007 普及组] 奖学金

bus_station @ 2019-09-30 08:53:34

# include <bits/stdc++.h>
using namespace std;

struct student
{
    int num;
    int c, m, e;
    int sum;
};
student child[310];

bool comp(student a, student b)
{
    if (a.sum > b.sum)return true;
    else if (a.sum < b.sum)return false;
    else
    {
        if (a.c > b.c)return true;
        else if (a.c < b.c)return false;
        else
        {
            if (a.num < b.num)return true;
            else return false;
        }
    }
}
int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        child[i].num = i;
        scanf("%d %d %d", &child[i].c, &child[i].m, &child[i].e);
        child[i].sum = child[i].c + child[i].m + child[i].e;
    }
    sort(child + 1, child + n + 1, comp);
    for (int i = 1; i <= 5; i++)
    {
        cout << child[i].num << " " << child[i].sum;
    }
    return 0;
}

救救孩子吧


by bus_station @ 2019-09-30 08:54:59

不知为何0分,大佬进来看看吧


by 杯子 @ 2019-09-30 09:11:39

#include<cstdio>
#include<algorithm>
int n;
struct node
{
    int total;
    int Chinese;
    int Math;
    int English;
    int num;
}student[301];
bool comp(node x,node y)
{
    if(x.total!=y.total)return x.total>y.total;
    if(x.Chinese!=y.Chinese)return x.Chinese>y.Chinese;
    return x.num<y.num;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%d",&student[i].Chinese,&student[i].Math,&student[i].English);
        student[i].num=i;
        student[i].total=student[i].Chinese+student[i].Math+student[i].English;
    }
    std::sort(student+1,student+n+1,comp);
    for(int i=1;i<=5;i++)
    {
        printf("%d %d\n",student[i].num,student[i].total);
    }
    return 0;
}

by bus_station @ 2019-09-30 09:34:11

@杯子 谢谢大佬


|