WA求助

P1093 [NOIP2007 普及组] 奖学金

Konnyaku_q @ 2023-09-22 16:06:48

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
int n;
struct feng
{
    int y,s,i;
    int num;
    int bian;
}ah[1000000]; 
long long cmp(feng a,feng b)
{
    if(a.num==b.num&&a.y!=b.y)
    {
        return a.y>b.y;
   }
    if(a.num==b.num&&a.y==b.y)
    {
        return a.bian>b.bian;
    }
    else
    {
        return a.num>b.num;
    }
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        ah[i].bian=i;
        cin>>ah[i].y>>ah[i].s>>ah[i].i;
        ah[i].num=ah[i].y+=ah[i].s+=ah[i].i;

    }
    sort(ah+1,ah+1+n,cmp);
    for(int i=0;i<5;i++)
    {
        cout<<ah[i].bian<<" "<<ah[i].num<<endl;
     } 

}

大佬们哪里做错了?


by Konnyaku_q @ 2023-09-22 16:12:10

六十分了,贴代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
int n;
struct feng
{
    int y,s,i;
    int num;
    int bian;
}ah[1000000]; 
long long cmp(feng a,feng b)
{
    if(a.num==b.num&&a.y!=b.y)
    {
        return a.y>b.y;
   }
    else if(a.num==b.num&&a.y==b.y)
    {
        return a.bian>b.bian;
    }
    else
    {
        return a.num>b.num;
    }
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        ah[i].bian=i;
        cin>>ah[i].y>>ah[i].s>>ah[i].i;
        ah[i].num=ah[i].y+=ah[i].s+=ah[i].i;

    }
    sort(ah+1,ah+1+n,cmp);
    for(int i=1;i<=5;i++)
    {
        cout<<ah[i].bian<<" "<<ah[i].num<<endl;
     } 

}

by tengzeyi @ 2023-09-30 21:17:46

太神奇了


by zouyinghan @ 2023-10-10 13:51:12

#include<bits/stdc++.h>
using namespace std;
struct student{
    int xuehao;
    int yu,shu,ying,sum;
}a[10000];
bool cmp(student x,student y)
{
    if(x.sum==y.sum)
    {
        if(x.yu==y.yu)
            return x.xuehao<y.xuehao;
        return x.yu>y.yu;
    }
    return x.sum>y.sum;
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        {
            cin>>a[i].yu>>a[i].shu>>a[i].ying;
            a[i].xuehao=i;
        }
    for(int i=1;i<=n;i++)
        a[i].sum=a[i].yu+a[i].shu+a[i].ying;
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=5;i++)
    cout<<a[i].xuehao<<" "<<a[i].sum<<endl;
 } 

这样用结构体可以简单很多,判断可能有一点”难“,我是蒟蒻,大佬勿喷!!!


|