1 solutions
-
0
思路分析
知识点: 结构体,多关键字排序(需提供 函数)
直接上代码AC代码
#include<bits/stdc++.h> using namespace std; struct node{ string name;//姓名 int cj;//成绩 }; int n; node studentt[25]; bool cmp(node a,node b){ if(a.cj != b.cj)return a.cj > b.cj; /*成绩不一样时,较大者在前*/ else return a.name < b.name; /*成绩相同时,按字典序排序*/ } signed main(){ cin >> n; for(int i = 1 ; i <= n ; i++){ cin >> studentt[i].name >> studentt[i].cj; } sort(studentt+1,studentt+n+1,cmp); /* sort(开始排序的位置,结束排序的位置,比较函数) */ for(int i = 1 ; i <= n ; i++){ cout << studentt[i].name << ' ' << studentt[i].cj << '\n'; } return 0; }
- 1
Information
- ID
- 36207
- Time
- 1000ms
- Memory
- 512MiB
- Difficulty
- 1
- Tags
- # Submissions
- 9
- Accepted
- 6
- Uploaded By