6点WA,大佬带

P1093 [NOIP2007 普及组] 奖学金

qwe123ljk @ 2022-10-29 22:23:39

#define _CRT_SECURE_NO_WARNINGS 
#include<stdio.h>
struct chengji
{
    int id;
    int yu;
    int shu;
    int wai;
    int he;
}stu[400];
int main()
{
    int n;
    scanf("%d", &n);
    int i,j,min,temp,k;
    for (i = 0; i < n; i++)
    {
        scanf("%d %d %d", &stu[i].yu, &stu[i].shu, &stu[i].wai);
    }
    for (i = 0; i < n; i++)
    {
        stu[i].id = i + 1;
        stu[i].he = stu[i].yu + stu[i].shu + stu[i].wai;
    }
    for (i = 0; i < n - 1; i++)
    {
        min = i;
        for (j = i + 1; j < n; j++)
        {
            if (stu[min].he > stu[j].he)
            {
                min = j;
            }
        }
        if (min != i)
        {
            temp = stu[min].he;
            stu[min].he = stu[i].he;
            stu[i].he = temp;
            temp = stu[min].id;
            stu[min].id = stu[i].id;
            stu[i].id = temp;
            temp = stu[min].yu;
            stu[min].yu = stu[i].yu;
            stu[i].yu = temp;
            for (k = 0; k < n; k++)
            {
                if (stu[k].he == stu[k + 1].he)
                {
                    if (stu[k].yu >= stu[k + 1].yu)
                    {
                        temp = stu[k].id;
                        stu[k].id = stu[k + 1].id;
                        stu[k + 1].id = temp;
                    }
                }
            }
        }
    }
    for (i = n - 1; i >= n - 5; i--)
    {
        printf("%d %d\n", stu[i].id, stu[i].he);
    }

    return 0;
}

by chenzhiyuan0923 @ 2022-10-29 22:40:42

#include<bits/stdc++.h>
using namespace std;
struct pep{
    int id,yu,su,en,tot;
};
pep v[5000+10];
int m,n;
bool cmp(pep x,pep y){
    if(x.tot!=y.tot) return x.tot>y.tot;
    if(x.yu!=y.yu) return x.yu>y.yu;
    return x.id <y.id ;
}                                       
int main(){                                                 
    cin>>n;
    for (int i=1;i<=n;i++) {
        cin>>v[i].yu >>v[i].su >>v[i].en ;
        v[i].id =i;
        v[i].tot=v[i].yu +v[i].su +v[i].en;
    }
    sort(v+1,v+1+n,cmp);
    for(int i=1;i<=5;i++) cout<<v[i].id <<' '<<v[i].tot <<endl;
    return 0;
}

by chenzhiyuan0923 @ 2022-10-29 22:41:35

@qwe123ljk


by qwe123ljk @ 2022-10-30 21:06:01

@xchenzhiyuan 没有学C++


by chenzhiyuan0923 @ 2022-10-30 21:23:42

@qwe123ljk emmmm


|