2014ACM/ICPC Asia Guangzhou station Song Jiang ' s rank list

Source: Internet
Author: User

Welcome to the Bestcoder-every Saturday night (with rice!) )
Song Jiang ' s rank listTime limit:2000/1000 MS (java/others) Memory limit:512000/512000 K (java/others)
Total submission (s): 673 Accepted Submission (s): 333


Problem Description "Shui Hu Zhuan", also "water Margin" was written by Shi Nai's--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 eve Ntually came to occupy Mout Liang (or Liangshan Marsh) and elected Song Jiang as their leader.

In order to encourage he military officers, Song Jiang always made a rank list after every battle. 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 Outlaws killed the same number of enemies, the one whose name is smaller in alphabet order had higher rank. Now, help Song Jiang to make the rank list and answer some queries based on the rank list.
Inputthere is no more than test cases.

For each test case:

The first line is a integer n (0<n<200), indicating that there be n outlaws.

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

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

Then M queries follow. Each query was a line containing an outlaw ' s name.
The input ends with n = 0
Outputfor each test case, print the Rank list first. For the contains a 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 do but whose name is S Maller in Alphabet order than his/hers. For each query, if the minor rank was 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 a answer for it.
Sample Input5 wusong luzhishen songjiang Lujunyi 1 huarong 5 wusong lujunyi luzhishen huarong Songjiang 0
Sample outputhuarong Songjiang luzhishen wusong Lujunyi 1 3 2 5 3 1 2

Exercises

(Map,sort sort)

Test instructions is very difficult to understand, drunk, in fact, quite simple a problem, the proposal is to put this rank ranking output, and then to each given the name of the output than it kills more than +1 people, and then output with it kills the same and the dictionary order than it small number of +1, if the number is 1 does not output;

Code:

1#include <stdio.h>2#include <string>3#include <algorithm>4#include <string.h>5#include <map>6 using namespacestd;7 Const intmaxn= About;8 structnode{9     Chars[Wuyi];Ten     intnum; One }; A Node DT[MAXN]; - intCMP (Node A,node b) { -     if(A.num!=b.num)returnA.num>B.num; the     Else if(strcmp (A.S,B.S) <0)return 1; -     Else return 0; - } -map<string,int>MP; + intMain () { -     Chartemp[ +]; +     intN,m,k,a,b,flot; A      while(~SCANF ("%d",&N), N) { at mp.clear (); -          for(intI=0; i<n;i++) scanf ("%s%d",dt[i].s,&dt[i].num); -Sort (dt,dt+n,cmp); -          for(intI=0; i<n;i++) -         { -printf"%s%d\n", dt[i].s,dt[i].num); inmp[dt[i].s]=i+1; -         } toscanf"%d",&M); +          while(m--){ -scanf"%s", temp); the          for(intI=0; i<n;i++){ *             if(strcmp (dt[i].s,temp) = =0) a=Dt[i].num; $         }Panax Notoginsengflot=0; k=0; -          for(intI=0; i<n;i++){ the             if(dt[i].num>a) k++; +             if(strcmp (dt[i].s,temp) <=0)if(A==dt[i].num) flot++; A         } the         if(flot>1) printf ("%d%d\n", K +1, flot); +         Elseprintf"%d\n", K +1); -     } $     } $     return  0; -}

2014ACM/ICPC Asia Guangzhou station Song Jiang ' s rank list

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.