zoukankan      html  css  js  c++  java
  • 杭电1718--Rank

    Rank

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 4411    Accepted Submission(s): 1707


    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
     

     

    Recommend
    lcy   |   We have carefully selected several similar problems for you:  1719 1717 1720 1707 1049 
    RE:  每个同学有学号、 根据学号找排名。 先把成绩单排一下, 整一下排名, 简单AC.
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <algorithm> 
     5 using namespace std;
     6 
     7 struct student
     8 {
     9     int hao, mark, pre;
    10 } num[1010];
    11 
    12 bool cmp(student hao, student mark)
    13 {
    14     return hao.mark > mark.mark; 
    15 }
    16 int main()
    17 {
    18     int a;
    19     while(~scanf("%d", &a))
    20     {
    21         int k = 0;
    22         for(; ;)
    23         {
    24                 
    25             int b, c;
    26             scanf("%d %d", &b, &c);
    27             if(b == 0 && c == 0)
    28                 break;
    29             else{
    30                 num[k].hao = b; num[k++].mark = c;
    31             }
    32         }
    33         sort(num, num + k, cmp);
    34         int Q = 1;                        //排名会有并列的。
    35         num[0].pre = Q; int temp = Q;
    36         for(int i = 1; i < k; i++)
    37         {
    38             if(num[i].mark == num[i-1].mark)
    39             {
    40                 num[i].pre = temp;
    41                 ++Q;
    42             }
    43             else
    44             {
    45                 ++Q;
    46                 num[i].pre = Q;
    47                 temp = Q;
    48             }
    49             //++Q;
    50         }
    51         int i;
    52         for(i = 0; i < k; i++)
    53             if(num[i].hao == a)
    54                 break;
    55         printf("%d
    ", num[i].pre);
    56     }
    57     return 0;
    58 }
  • 相关阅读:
    JArray
    签名和验签
    private、protected、public和internal的区别
    DataTime.Now.Ticks
    NameValuePair 简单名称值对节点类型
    01安卓目录结构
    SDK目录结构
    java wait和notify及 synchronized sleep 总结
    安卓常用的第三方框架
    OkHttp使用教程
  • 原文地址:https://www.cnblogs.com/soTired/p/4727392.html
Copyright © 2011-2022 走看看