📄 excel排序.txt
字号:
//test
#include <cstdio>
#include <string>
#include <cmath>
#include <stack>
#include <algorithm>
using namespace std;
const int NMAX = 100100;
struct node {
char num[10],name[10];
int score;
}stu[NMAX];
bool cmp1(const node n1,const node n2) {
int cmp = strcmp(n1.num,n2.num);
return (cmp < 0);
}
bool cmp2(const node n1,const node n2) {
int cmp = strcmp(n1.name,n2.name);
if (cmp != 0) return (cmp < 0);
else {
cmp = strcmp(n1.num,n2.num);
return (cmp < 0);
}
}
bool cmp3(const node n1,const node n2) {
if (n1.score != n2.score) return (n1.score < n2.score);
else {
int cmp = strcmp(n1.num,n2.num);
return (cmp < 0);
}
}
int n,c;
int main() {
int cas = 1;
while (scanf("%d %d",&n,&c),n) {
int i;
for (i=0;i<n;i++) {
scanf("%s %s %d",stu[i].num,stu[i].name,&stu[i].score);
}
if (c == 1) sort(stu,stu+n,cmp1);
else if (c == 2) sort(stu,stu+n,cmp2);
else if (c == 3) sort(stu,stu+n,cmp3);
printf("Case %d:\n",cas ++);
for (i=0;i<n;i++) printf("%s %s %d\n",stu[i].num,stu[i].name,stu[i].score);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -