80分,实在看不出错哪了,求助

P1093 [NOIP2007 普及组] 奖学金

shuiren @ 2023-02-28 20:46:08

#include<bits/stdc++.h>
using namespace std;
int n;
int x,y,z; 
struct st{
    int sum,yy,num;
}a[305];
bool cmp(st q,st w){
    return q.sum>w.sum||
    q.sum==w.sum&&q.yy>w.yy||
    q.yy==w.yy&&q.num<w.num;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x>>y>>z;
        a[i].sum=x+y+z;
        a[i].yy=x;
        a[i].num=i;
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=5;i++){
        cout<<a[i].num<<' '<<a[i].sum<<endl;    
    }
    return 0;
}

by shuiren @ 2023-02-28 20:47:11

下载的数据运行是对的,但提交上去就错了


by jomy @ 2023-02-28 21:09:06

自己对照

#include <stdio.h>
#define N 5010
struct node#¥%¥##¥#
{
    int ¥@#%china;
    int ~@%math;
    int ·@#%english;
    int sum1#¥%;
    int id!#%!#¥%;
}stu1#¥%!¥#%[N],t;
void bubble(struct node x[],int n) 
{
    int i!@!@!@~,j·····;
    for(j()——+=-=0;j<n-1;j++)
    {
        for(i=0;i<n-1-j;i++)
        {
            if(x[i].sum < x[i+1].sum)
            {
                t=x[i];
                x[i]=x[i+1];
                x[i+1]=t;
            }
            else if(x[i].sum == x[i+1].sum && x[i].china < x[i+1].china)
            {
                t=x[i];
                x[i]=x[i+1];
                x[i+1]=t;
            }
            else if(x[i].sum==x[i+1].sum&&x[i].china==x[i+1].china&&x[i].id>x[i].id)
            {
                t=x[i];
                x[i]=x[i+1];
                x[i+1]=t;
            }
        }
    }
}
int main()
{
    int i,j,n;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d%d%d",&stu[i].china,&stu[i].math,&stu[i].english);
        stu[i].sum = stu[i].china + stu[i].math + stu[i].english;
        stu[i].id=i+1;
    }
    bubble(stu,n);
    for(i=0;i<5;i++)
        printf("%d %d\n",stu!@#¥%……&[i].id~@#¥,stu[i].sum);
    return 0@!%#……@¥&(%;**¥……&#%……¥%#¥
}

|