首页 > 试题广场 >

成绩排序

[编程题]成绩排序
  • 热度指数:45126 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
用一维数组存储学号和成绩,然后,按成绩排序输出。

输入描述:
输入第一行包括一个整数N(1<=N<=100),代表学生的个数。
接下来的N行每行包括两个整数p和q,分别代表每个学生的学号和成绩。


输出描述:
按照学生的成绩从小到大进行排序,并将排序后的学生信息打印出来。
如果学生的成绩相同,则按照学号的大小进行从小到大排序。
示例1

输入

3
1 90
2 87
3 92

输出

2 87
1 90
3 92
头像 靓仔兴
发表于 2021-01-30 00:48:49
#include<iostream> #include<algorithm> using namespace std; struct Student{ int no; int score; }; bool compared(Student std1,Stud 展开全文
头像 渺小小螃蟹
发表于 2021-05-09 11:56:58
//结构体是好东西啊 #include<iostream> #include<algorithm> using namespace std; struct Student { int id; int score; }; bool compare(Stud 展开全文
头像 帅呆呆~
发表于 2022-03-05 14:13:15
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; //定义学生结构体 struct Student { int number; int score; 展开全文
头像 Javker丶鑫
发表于 2021-02-03 20:15:40
主要思路: 创建两个一维数组对应学号和成绩,然后冒泡排序同时维护两个数组内值,在应用层实现同时替换(不会list集合QAQ)。然后使用双指针法设置left,right两个变量形成滑动窗口,找到一个区间的值来进行学号的排序。学号的排序只要确定同分的区间就很容易的调用Arrays.sort(int 展开全文
头像 DioDid
发表于 2022-01-20 16:33:20
#include <stdio.h> #include <stdlib.h> typedef struct Grade { int Order; int Point; }Grade; int cmp(const void *a,const void *b) 展开全文
头像 牛客892450047号
发表于 2024-01-16 00:00:15
#include <iostream> using namespace std; typedef pair<int,int>pii; #include<vector> #include<algorithm> bool cmp1(pii a,pii b) 展开全文
头像 我不是匠人
发表于 2021-04-03 19:32:29
思路 重写比较器 注意输出格式 import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Main { 展开全文
头像 乌龟狗的齐天大圣
发表于 2023-02-17 18:41:50
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; struct Student{ int number; int score; }; 展开全文
头像 牛客38898293号
发表于 2023-07-03 15:38:10
#include "iostream" #include "map" #include <utility> #include<algorithm> #include<vector> using namespace std; map<int, int>m 展开全文
头像 MrMello
发表于 2023-03-23 17:12:07
#include <stdio.h> int main(){ int number; scanf("%d", &number); //定义一个student结构体,包含学号和成绩 struct student{ int num; 展开全文