主站
DreamJudge
院校信息
专业题库
模拟考试
机试真题
专业课程
讨论区
兑换中心
登录
注册
发布
以下题解仅供学习参考使用。
抄袭、复制题解,以达到刷AC率/AC数量或其他目的的行为,在N诺是严格禁止的。
N诺非常重视学术诚信。此类行为将会导致您成为作弊者。具体细则请查看N诺社区规则。
williams
2024年3月7日 14:24
成绩排序2.0 题解:c
P1159
回复 8
|
赞 0
|
浏览 477
#include <stdio.h> #include <stdbool.h> #include <math.h> #include <string.h> //object:按照成绩升序排列,成绩相同则按照学号升序排列 struct student{ int number,score; }data[1000],temp; int main(void){ int n,j,u; while(scanf("%d",&n)!=EOF){ for(int i=0;i<...
orderrr
2024年2月25日 15:39
成绩排序2.0 题解:
P1159
回复 0
|
赞 0
|
浏览 340
思想: 自定义 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
|
浏览 400
#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; ...
fzh
2024年1月29日 04:16
成绩排序2.0 题解:用pair 实现排序
P1159
回复 0
|
赞 0
|
浏览 286
#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
|
浏览 402
#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
|
浏览 4.6k
#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
|
浏览 326
#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
|
浏览 735
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
|
浏览 356
注意必须自定义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
|
浏览 2.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) ...
1
2
3
题目
成绩排序2.0
题解数量
27
发布题解
热门题解
1
P1159 成绩排序2.0
2
成绩排序2.0 (C++)题解:
3
成绩排序2.0 题解:sort函数实现
4
c 简单数组冒泡
5
比较容易理解的作法
6
小坑的地方在于,必须要初始化一个student,然后push_back.
7
成绩排序2.0 题解:c++ sort函数+结构体
8
c++(短代码)
9
成绩排序2.0 题解:
10
成绩排序2.0 题解: