zoukankan      html  css  js  c++  java
  • Song Jiang's rank list

     Song Jiang's rank list
    Time Limit:1000MS     Memory Limit:512000KB     64bit IO Format:%I64d & %I64u

    Description

    《Shui Hu Zhuan》,also 《Water Margin》was written by Shi Nai'an -- an writer of Yuan and Ming dynasty. 《Shui Hu Zhuan》is one of the Four Great Classical Novels of Chinese literature. It tells a story about 108 outlaws. They came from different backgrounds (including scholars, fishermen, imperial drill instructors etc.), and all of them eventually came to occupy Mout Liang(or Liangshan Marsh) and elected Song Jiang as their leader. 

    In order to encourage his military officers, Song Jiang always made a rank list after every battle. In the rank list, all 108 outlaws were ranked by the number of enemies he/she killed in the battle. The more enemies one killed, one's rank is higher. If two outlaws killed the same number of enemies, the one whose name is smaller in alphabet order had higher rank. Now please help Song Jiang to make the rank list and answer some queries based on the rank list.
     

    Input

    There are no more than 20 test cases. 

    For each test case: 

    The first line is an integer N (0<N<200), indicating that there are N outlaws. 

    Then N lines follow. Each line contains a string S and an integer K(0<K<300), meaning an outlaw's name and the number of enemies he/she had killed. A name consists only letters, and its length is between 1 and 50(inclusive). Every name is unique. 

    The next line is an integer M (0<M<200) ,indicating that there are M queries. 

    Then M queries follow. Each query is a line containing an outlaw's name. 
    The input ends with n = 0
     

    Output

    For each test case, print the rank list first. For this part in the output ,each line contains an outlaw's name and the number of enemies he killed. 

    Then, for each name in the query of the input, print the outlaw's rank. Each outlaw had a major rank and a minor rank. One's major rank is one plus the number of outlaws who killed more enemies than him/her did.One's minor rank is one plus the number of outlaws who killed the same number of enemies as he/she did but whose name is smaller in alphabet order than his/hers. For each query, if the minor rank is 1, then print the major rank only. Or else Print the major rank, blank , and then the minor rank. It's guaranteed that each query has an answer for it.
     

    Sample Input

    5
    WuSong 12
    LuZhishen 12
    SongJiang 13
    LuJunyi 1
    HuaRong 15
    5
    WuSong
    LuJunyi
    LuZhishen
    HuaRong
    SongJiang
    0
     

    Sample Output

    HuaRong 15
    SongJiang 13
    LuZhishen 12
    WuSong 12
    LuJunyi
    1 3
    2
    5
    3
    1
    2
     
     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<algorithm>
     4 using namespace std;
     5 struct st
     6 {
     7     char name[303];
     8     int kill;
     9 }data[202];
    10 int cmp(st a,st b)//注意排序就好。
    11 {
    12     if(a.kill!=b.kill)
    13           return a.kill > b.kill ;
    14     else if(strcmp(a.name,b.name)<0)
    15           return 1;
    16     else
    17           return 0;
    18 }
    19 int main()
    20 {
    21   //  freopen("a.txt" , "r" , stdin ) ;
    22     int i,j,l,n,m,k,t;
    23     char s[302];
    24     while(scanf("%d",&n)&&n)
    25     {
    26         for(i=0;i<n;i++)
    27             scanf("%s %d",data[i].name,&data[i].kill);
    28 
    29         sort(data,data+n,cmp);
    30 
    31         for(i=0;i<n;i++)
    32         {
    33              printf("%s %d
    ",data[i].name,data[i].kill);
    34         }
    35         scanf("%d",&m);
    36         for(i=0;i<m;i++)
    37         {
    38             scanf("%s",s);
    39             for(l=0;l<n;l++)
    40             {
    41                 if(strcmp(s,data[l].name)==0)
    42                 {
    43                     k=l;
    44                     t=1;
    45                     for(j=k-1;j>=0;j--)
    46                     {
    47                         if(data[k].kill==data[j].kill)
    48                            t++;
    49                     }
    50                     if(t==1)
    51                         printf("%d
    ",k+1);
    52                     else
    53                         printf("%d %d
    ",k-t+2,t);
    54                }
    55            }
    56         }
    57     }
    58     return 0;
    59 }
    sort(a , a+n, cmp)
  • 相关阅读:
    keras模块学习之泛型模型学习笔记
    keras模块学习之Sequential模型学习笔记
    keras模块学习之model层【重点学习】
    keras模块学习之层(layer)的使用-笔记
    keras模块学习之-参数初始化与对象调用-笔记
    keras模块学习之-激活函数(activations)--笔记
    keras模块学习之-目标函数(objectives)笔记
    业务驱动下的项目管理实践
    关于跨团队合作的一些思考
    当我们谈论计划时我们在谈论什么
  • 原文地址:https://www.cnblogs.com/get-an-AC-everyday/p/4268509.html
Copyright © 2011-2022 走看看