球条

P1093 [NOIP2007 普及组] 奖学金

uua___ @ 2024-08-21 16:52:40

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

bool cmp(int x,int y)
{
    return x>y;
}

int a[310],y[310],s[310],e[310],q[310];
int main()
{

    int n;cin>>n;
        for(int i=1;i<=n;i++)
    {
        cin>>y[i]>>s[i]>>e[i];
        a[i]=y[i]+s[i]+e[i];
        q[i]=i;

    }
    sort(a+1,a+n+1,cmp);
        for(int i=1;i<=n;i++)
        {
            int temp=0;
            if(a[i]==a[i+1])
            {
                if(y[i]<y[i+1])
                {
                temp=a[i];
                a[i]=a[i+1];
                a[i+1]=temp;
                temp=0;

                }

            }

        }

                for(int i=1;i<=5;i++)
            {
                cout<<q[i]<<" "<<a[i]<<endl;
            }

    return 0; 
}

by Hyper_zero @ 2024-08-21 16:56:33

@uua___ 用结构体,哥们


by Hyper_zero @ 2024-08-21 16:58:01

@uua___ 你的学号没有跟着分数改变


by joe_001 @ 2024-08-28 16:33:49

参考:

#include<bits/stdc++.h>
using namespace std;
long long n,a[1001][6];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        a[i][1]=i;
        cin>>a[i][2]>>a[i][3]>>a[i][4];
        a[i][5]=a[i][2]+a[i][3]+a[i][4];
    }
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
            if(a[j][5]>a[i][5] || a[j][5]==a[i][5] && a[j][2]>a[i][2] || a[j][2]==a[i][2] && a[j][1]<a[i][1])
            {
                swap(a[i][1],a[j][1]);
                swap(a[i][2],a[j][2]);
                swap(a[i][3],a[j][3]);
                swap(a[i][4],a[j][4]);
                swap(a[i][5],a[j][5]);
            }
    for(int i=1;i<=5;i++)
        cout<<a[i][1]<<" "<<a[i][5]<<endl;
    return 0;
}

by joe_001 @ 2024-08-28 16:35:04

@uua___

求关!


|