HDU 1.3.6 Rank

来源:互联网 发布:青华ug8.5编程视频教程 编辑:程序博客网 时间:2024/06/03 20:42
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
2007010120070102 10020070101 3320070103 2220070106 330 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;  }  

0 0