excel排序.txt
来自「浙江大学研究生复试上机题目及解答。欢迎大家下载。」· 文本 代码 · 共 47 行
TXT
47 行
//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 + =
减小字号Ctrl + -
显示快捷键?