枯了,全RE。

P1093 [NOIP2007 普及组] 奖学金

Register_int @ 2021-01-12 19:08:59

错在哪啊啊啊啊啊啊啊啊

#include<bits/stdc++.h>
using namespace std;
struct mark{
    int node;
    int y;
    int s;
    int e;
    int sum;
};
bool cmp(mark a,mark b){
    if(a.sum == b.sum){
        if(a.y == b.y){
            if(a.s == b.s){
                return a.e > b.e;
            }
            return a.s > b.s;
        }
        return a.y > b.y;
    }
    return a.sum > b.sum;
}
int main(){
    int n;
    cin >> n;
    mark a[n];
    for(int i = 0; i < n; i++){
        scanf("%d %d %d",a[i].y,a[i].s,a[i].e);
        a[i].node = i + 1;
        a[i].sum = a[i].y + a[i].s + a[i].e;
    }
    sort(a,a + n,cmp);
    for(int i = 0; i < 5; i++){
        printf("%d %d\n",a[i].node,a[i].sum);
    }
}

by PPL_ @ 2021-01-12 19:14:56

为什么scanf没有&


by CGDGAD @ 2021-01-12 19:23:28

请不要使用 mark a[n] 这种语法,请放在全局变量然后写成 mark a[10001]


by E1_de5truct0r @ 2021-01-12 19:24:08

@NSObject 对的,这样容易爆


by CGDGAD @ 2021-01-12 19:27:58

#include<bits/stdc++.h>
using namespace std;
struct mark{
    int node;
    int y;
    int s;
    int e;
    int sum;
};
bool cmp(mark a,mark b){
    if(a.sum == b.sum){
        if(a.y == b.y){
            if(a.s == b.s){
                return a.e > b.e;
            }
            return a.s > b.s;
        }
        return a.y > b.y;
    }
    return a.sum > b.sum;
}
mark a[10001]; // 放在全局变量,开成一个大数组。
int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        scanf("%d %d %d",&a[i].y,&a[i].s,&a[i].e); //scanf这里一定要加取址符"&"(输入整个字符串的时候不用,其他的时候基本都要用)
        a[i].node = i + 1;
        a[i].sum = a[i].y + a[i].s + a[i].e;
    }
    sort(a,a + n,cmp);
    for(int i = 0; i < 5; i++){
        printf("%d %d\n",a[i].node,a[i].sum);
    }
}

by E1_de5truct0r @ 2021-01-12 19:29:42

#include<bits/stdc++.h>
using namespace std;
struct mark{
    int node;
    int y;
    int s;
    int e;
    int sum;
};
bool cmp(mark a,mark b){
    if(a.sum == b.sum){
        if(a.y == b.y){
            return a.node < b.node;//学号小的排在前面, 不是按照语数英(注意读题)
        }
        return a.y > b.y;
    }
    return a.sum > b.sum;
}
int main(){
    int n;
    cin >> n;
    mark a[n];
    for(int i = 0; i < n; i++){
        scanf("%d %d %d",&a[i].y,&a[i].s,&a[i].e); //scanf这里一定要加取址符"&"(输入整个字符串的时候不用,其他的时候基本都要用)
        a[i].node = i + 1;
        a[i].sum = a[i].y + a[i].s + a[i].e;
    }
    sort(a,a + n,cmp);
    for(int i = 0; i < 5; i++){
        printf("%d %d\n",a[i].node,a[i].sum);
    }
}

|