首页
DreamJudge
院校信息
考研初试
机试真题
讨论区
兑换中心
登录
注册
上岸
以下题解仅供学习参考使用。
抄袭、复制题解,以达到刷AC率/AC数量或其他目的的行为,在N诺是严格禁止的。
N诺非常重视学术诚信。此类行为将会导致您成为作弊者。具体细则请查看N诺社区规则。
orderrr
2024年2月25日 15:39
成绩排序2.0 题解:
P1159
回复 0
|
赞 0
|
浏览 1.0k
思想: 自定义 cmp 判断方法, 当 分数一样就 return p.index < q.index // index 是学生编号 #include <bits/stdc++.h> using namespace std; struct student { int index; int value; }; bool cmp(student x, student y) { if (x.value == y.value) { return x.index < y.i...
小王桐学
2024年1月31日 22:15
成绩排序2.0 题解:C
P1159
回复 0
|
赞 0
|
浏览 1.1k
#include <stdio.h> typedef struct{ int x; int s; }Student; //排序:先按成绩s从小到大;如果学生的成绩相同,则按照学号的大小进行从小到大排序。 void Sort(Student stu[],int n) { //先按学号从小到大排序(学号互异) //再进行稳定排序(从最后向前每次选择最大的数放最后) int i,j; Student temp; for(i = 0; i < n-1; i++) //学号排序 for(j = 1; j < n-i; ...
carrot_huan
2024年1月29日 04:16
成绩排序2.0 题解:用pair 实现排序
P1159
回复 0
|
赞 0
|
浏览 1.3k
#include<bits/stdc++.h> using namespace std; int cmp(pair<int, int>a, pair<int, int >b) { if (a.second == b.second) return a.first < b.first; else return a.second < b.second; } int main() { &...
Cookie‘s AE86
2024年1月23日 14:37
成绩排序2.0 题解:sort函数实现
P1159
回复 0
|
赞 1
|
浏览 1.1k
#include <bits/stdc++.h> using namespace std ; typedef struct student{ //定以结构体 int id ; //学号 int score ; //成绩 } Student ; bool cmp(Student a ,Student b){ if(a.score == b.score) return a.id < b.id; //成绩相等取学号小的 else return a.score < b.score ; } ...
LianG_nnuo
2022年11月15日 10:39
c 简单数组冒泡
P1159
回复 1
|
赞 1
|
浏览 6.1k
#include<stdio.h> #include<stdlib.h> #include<string.h> /* 输入第一行包括一个整数N(1<=N<=100),代表学生的个数。 接下来的N行每行包括两个整数p和q,分别代表每个学生的学号和成绩。 输出描述: 按照学生的成绩从小到大进行排序,并将排序后的学生信息打印出来。 如果学生的成绩相同,则按照学号的大小进行从小到大排序。 输入输出样例 输入样例#: 复制 3 1 90 2 87 3 92 输出样例#: 复制 2 87 1 90 3 92 *...
小李122333
2024年1月14日 20:18
成绩排序2.0 题解:c++ sort函数+结构体
P1159
回复 0
|
赞 1
|
浏览 851
#include <bits/stdc++.h> using namespace std; struct node{ int num; int score; }; int cmp(node n1,node n2){ if(n1.score==n2.score){ return n1.num<n2.num; } return n1.score<n2.score; } int main(){ int n; while(cin>>n){ ...
Syou
2023年8月14日 22:14
成绩排序2.0 题解:
P1159
回复 0
|
赞 0
|
浏览 1.3k
C++ cmp函数保证先比较分数score,分数相同比较学号id #include <iostream> #include <string> #include <algorithm> #include <vector> using namespace std; struct Student{ int id; int score; }; bool cmp(const Student& student1, const Student& student2){ if(student1.sco...
dongqing
2023年7月31日 09:13
成绩排序2.0 题解:
P1159
回复 0
|
赞 0
|
浏览 885
注意必须自定义cmp函数因为输入是结构体,所以不能直接在sort里面比较会出错,而采用定义一个实现想要功能的cmp来保证同等分数的时候学号优先,不同分数的时候 分数小的在前。 注意结构体定义的样子和结构体数组的定义。 #include<bits/stdc++.h> using namespace std; struct student { int num; int score; }; bool cmp(student x,student y) { if(x.score==y.score) return x.nu...
Keeshpku
2023年3月20日 00:42
小坑的地方在于,必须要初始化一个student,然后push_back
P1159
回复 0
|
赞 1
|
浏览 3.0k
#include <bits/stdc++.h> using namespace std; struct Student{ int id; int score; }; bool cmp(Student x1, Student x2){ if(x1.score == x2.score) return x1.id < x2.id; else{return x1.score < x2.score;} } int main(){ int n; while(scanf("%d",&n) ...
huangdashuaige
2023年2月17日 15:13
P1159 成绩排序2.0
P1159
回复 0
|
赞 1
|
浏览 3.2k
#include <iostream> #include <algorithm> using namespace std; typedef struct st_nc{ //声明结构体 int num;//学号 float sco;//成绩 }ST; bool cmp(ST x,ST y){ //sort排序的规则 if(x.sco==y.sco) &nbs...
1
2
3
4
题目
成绩排序2.0
题解数量
36
发布题解
在线答疑
热门题解
1
成绩排序2.0 题解:记录一下
2
成绩排序2.0 题解:
3
成绩排序2.0 题解:暴力至高
4
成绩排序2.0 题解:
5
成绩排序2.0 题解:为什么通过数据只有75%啊 球球了 帮我找出错误测试数据吧 感谢
6
成绩排序2.0 题解:改了好多次了,一直都通过不了
7
成绩排序2.0 题解:
8
成绩排序2.0 题解:
9
成绩排序2.0 (C++)题解:
10
成绩排序2.0 题解: