文章

71

粉丝

97

获赞

5

访问

17.9k

头像
1159 为什么会超时
我要提问
发布于2024年1月27日 18:48
阅读数 284

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include <stdlib.h>
using namespace std;

struct student{
    int  no;
    int grade;
}student[105];
bool cmp(struct student a,struct student b){
    if(a.grade==b.grade) return a.no<b.no;
    else return a.grade<b.grade;
}
int main(){
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        scanf("%d",student[i].no);
        scanf("%d",student[i].grade);
    }
    sort(student,student+N,cmp);
    for(int i=0;i<N;i++){
        printf("%d %d\n",student[i].no,student[i].grade);
    }
    return 0;
}

登录查看完整内容


登录后发布评论

1 条评论
snake
2024年1月27日 19:32

你的输入有问题

scanf对应的变量前面要加&

赞(0)