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 }
  • 相关阅读:
    简单工厂、工厂方法和抽象工厂的学习笔记
    单一职责原则,开-闭原则,依赖倒置原则
    我对面向对象设计的理解——Java接口和Java抽象类
    高可用与负载均衡的区别
    应用交付、负载均衡(Load balancing)、高可用、F5
    四种常见的 POST 提交数据方式
    Git fetch和git pull的区别
    苹果Mac OS X显示隐藏文件的方法
    Appium教程---Client/Server Architecture
    UNIX网络编程——使用线程的TCP回射服务器程序
  • 原文地址:https://www.cnblogs.com/soTired/p/4727392.html
Copyright © 2011-2022 走看看