|
Problem Description
Jackson wants to know his rank in the class. The professor has posted a list of student numbers and marks. Compute Jackson’s rank in class; that is, if he has the top mark(or is tied for the top mark) his rank is 1; if he has the
second best mark(or is tied) his rank is 2, and so on.
|
|
Input
The input consist of several test cases. Each case begins with the student number of Jackson, an integer between 10000000 and 99999999. Following the student number are several lines, each containing a student number between 10000000
and 99999999 and a mark between 0 and 100. A line with a student number and mark of 0 terminates each test case. There are no more than 1000 students in the class, and each has a unique student number.
|
|
Output
For each test case, output a line giving Jackson’s rank in the class.
|
|
Sample Input
20070101 20070102 100 20070101 33 20070103 22 20070106 33 0 0 |
|
Sample Output
2 |
|
Source
2007省赛集训队练习赛(2)
|
|
Recommend
lcy
|
#include<stdio.h>
#include"algorithm"
using namespace std;
struct record{
long ID;
int mark;
};
record stu[1000];
int main()
{
//freopen("f://in.txt", "r", stdin);
//freopen("f://out.txt", "w", stdout);
long stuID;
int markTemp,jacksonIndex;
long IDtemp;
while (scanf("%ld",&stuID) != EOF)
{
memset(stu, 0, sizeof(stu));
int len = 0;
while (1)
{
scanf("%ld %d", &IDtemp, &markTemp);
if (markTemp == 0 && IDtemp==0)
break;
else
{
if (IDtemp == stuID)
jacksonIndex = len;
stu[len].ID = IDtemp;
stu[len++].mark = markTemp;
}
}
int rank = 1;
for (int i = 0; i < len; i++)
{
if (stu[i].ID != stuID&&stu[i].mark > stu[jacksonIndex].mark)
rank++;
}
printf("%d\n", rank);
}
return 0;
}
本文介绍了一个简单程序,用于根据学生的成绩来计算特定学生(如Jackson)在班级中的排名。输入包括多个测试案例,每个案例首先给出特定学生的学生编号,随后是一系列包含其他学生编号及其成绩的数据。程序读取这些数据,并确定特定学生相对于班级其他成员的成绩排名。
323

被折叠的 条评论
为什么被折叠?



