求救~~50分,重复分数的标题部分错了

P1093 [NOIP2007 普及组] 奖学金

sanmu_kangping @ 2023-08-21 18:20:19

#include<bits/stdc++.h> 
using namespace std;
int main()
{
    long long n,i,a[10005],s[10005]={0},b,c,j,t,r[100005];
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i]>>b>>c;
        s[i]=a[i]+b+c;
        r[s[i]]=i;
    } 
    for(i=n;i>=1;i--)
    {
        for(j=1;j<i;j++)
        {
            if(s[j]>s[j+1])
            {
                t=s[j];
                s[j]=s[j+1];
                s[j+1]=t;
            }
            else if(s[j]==s[j+1])
            {
                if(a[j]<a[j+1])
                {
                    t=s[j];
                s[j]=s[j+1];
                s[j+1]=t;
                }
                else if(a[j]==a[j+1])
                {
                    r[s[i]]=j;
                    if(j>j+1)
                    {
                        t=s[j];
                        s[j]=s[j+1];
                        s[j+1]=t;
                    }
                }
            }
        }
     } 
    for(i=n;i>=n-4;i--)
    {
        cout<<r[s[i]]<<" "<<s[i]<<endl;
    }
    return 0;
}

by sakura_erii @ 2023-08-24 15:38:20

#include<bits/stdc++.h>
using namespace std;
struct woshishenlilinghuadegou
{
    int num;
    int ch,ma,en;
    int sum;
};
woshishenlilinghuadegou a[10000];
bool cmp(woshishenlilinghuadegou x,woshishenlilinghuadegou y)
{
    if(x.sum==y.sum && x.ch==y.ch) return x.num<y.num;
    if(x.sum==y.sum) return x.ch>y.ch;
    return x.sum>y.sum;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i].ch>>a[i].ma>>a[i].en;
        a[i].num=i+1; 
        a[i].sum=a[i].ch+a[i].ma+a[i].en;
    }
    sort(a,a+n,cmp);
    for(int i=0;i<5;i++)
    {
        cout<<a[i].num<<' '<<a[i].sum<<endl;
    }
    return 0;
}

如果总分一样,那么返回语文的大小排序

否则排序总分

这个题建议用结构体排序,建议去学一下喔


by Liyunze123 @ 2023-08-25 14:53:02

确定是学号小的排前面吗


by Miracle1024 @ 2023-10-01 23:51:46

@sakura_erii 《woshishenlilinghuadegou》

我是山里灵活的狗XD


|