解题思路:
注意事项:
参考代码:
#include<iostream>
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct student
{
char id[9];
char name[9];
int fen;
};
bool cmp1(struct student a,struct student b)
{
return strcmp(a.id,b.id)<0;
}
bool cmp2(struct student a,struct student b)
{
int tmp=strcmp(a.name,b.name);
if(tmp!=0)
{
return tmp<0;
}
else
{
return strcmp(a.id,b.id)<0;
}
}
bool cmp3(struct student a,struct student b)
{
if(a.fen==b.fen)
return strcmp(a.id,b.id)<0;
else
return a.fen<b.fen;
}
struct student st[100005];
int main()
{
int i=1;
int n;
while(cin>>n)
{
int t;
cin>>t;
if(n==0)
continue;
printf("Case %d:\n",i++);
for(int i=0; i<n; i++)
scanf("%s%s%d",st[i].id,st[i].name,&st[i].fen);
switch(t)
{
case 1:
sort(st,st+n,cmp1);
break;
case 2:
sort(st,st+n,cmp2);
break;
case 3:
sort(st,st+n,cmp3);
break;
}
for(int i=0; i<n; i++)
printf("%s %s %d\n",st[i].id,st[i].name,st[i].fen);
}
}
0.0分
0 人评分
点我有惊喜!你懂得!浏览:1437 |
数组输出 (C语言代码)浏览:811 |
简单的a+b (C语言代码)浏览:583 |
字符串比较 (C语言代码)答案错误????浏览:641 |
【排队买票】 (C语言代码)浏览:944 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:616 |
数对 (C语言代码)浏览:762 |
核桃的数量 (C语言代码)浏览:726 |
C二级辅导-求偶数和 (C语言代码)浏览:707 |
简单的a+b (C语言代码)浏览:542 |