- Description
每学期考试结束,教务处老师都要对学生成绩进行一些统计。请你帮助教务处老师对学生成绩从高到低进行排名。成绩相同,排名序号相同,先后出现顺序与原始次序相同。
- Input
第一行是一个正整数:测试用例数目,最多为100。之后,每个测试用例包括:
l 第1行,含一个整数n:1≤n≤100,表示学生数
l n行,每一行含一个字符串(长度不超过10)、一个整数,分别表示学生的学号、成绩
- Output
对于每个测试用例:
l 输出“Case #:”,#表示序号
l 输出n行,每一行含排名序号、学生学号、成绩
注意:输出部分的结尾要求包含一个多余的空行。
- Sample Input
2
5
B05021924 90
B07030901 91
B07030419 90
B07021027 93
B06060606 87
1
D0408 100
- Sample Output
Case 1:
1 B07021027 93
2 B07030901 91
3 B05021924 90
3 B07030419 90
5 B06060606 87
Case 2:
1 D0408 100
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct stu
{
char name[20];
int id;
int score;
};
stu st[110];
int cmp(stu a,stu b)
{
if(a.score!=b.score)
return a.score>b.score;
return a.id<b.id;
}
int main()
{
//freopen("in.txt","r",stdin);
int n,m,i;
scanf("%d",&n);
for(int t=1;t<=n;t++)
{
int x;
printf("Case %d:\n",t);
scanf("%d",&m);
for(i=0;i<m;i++)
{
scanf("%s %d",st[i].name,&st[i].score);
st[i].id=i;
}
sort(st,st+m,cmp);
printf("1 %s %d\n",st[0].name,st[0].score);
x=1;
for(i=1;i<m;i++)
{
if(st[i].score!=st[i-1].score)x=i+1;
printf("%d %s %d\n",x,st[i].name,st[i].score);
}
}
return 0;
}