1718 Rank

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

 

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <stdio.h>
 4 #include <string.h>
 5 #include <math.h>
 6 using namespace std;
 7 int main()
 8 {
 9      int JK,haoma,a[1005],data,k;
10      while(cin>>JK)
11      {
12          k=0;
13          while(~scanf("%d%d",&haoma,&a[k]))
14          {
15              k++;
16              if(haoma==JK)
17              data=a[k-1];
18              if(haoma==0&&a[k-1]==0)
19              break;
20          }
21          sort(a,a+k);
22          for(int i=0;i<k;i++)
23          if(data<a[i])
24          {
25              data=k-i+1;
26              break;
27          }
28          cout<<data<<endl;
29      }
30      return 0;
31 }
View Code

 

posted @ 2016-03-14 21:47  Wally的博客  阅读(261)  评论(0编辑  收藏  举报