Song Jiang ' s rank list
Time limit:2000/1000 MS (java/others) Memory limit:512000/512000 K (java/others)
Total submission (s): Accepted submission (s): 8
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 input5wusong 12LuZhishen 12SongJiang 13LuJunyi 1HuaRong 155WUSONGLUJUNYILUZHISHENHUARONGSONGJIANG0
Sample outputhuarong 15SongJiang 13LuZhishen 12WuSong 12LuJunyi 13 25312
• This problem is too pit,,, do not know why the sorting function is wrong. Later changed to:
if (strcmp (X.NAME1,Y.NAME1) < 0) return 1;
else return 0;
Before, do not know the reason, but later still more attention. AC Code:
1#include <iostream>2#include <stdio.h>3#include <algorithm>4#include <cstring>5#include <string.h>6#include <math.h>7#include <queue>8#include <stack>9#include <stdlib.h>Ten#include <map> One using namespacestd; A #defineLL Long Long - #defineSF (a) scanf ("%d",& (a)); - the - #defineN 320 - - structlnode{ + Charname[ -]; - Charname1[ -]; + intnum; A }f[n]; at - intcmdConst structLnode x,Const structLnode y) { - if(X.num = =y.num) - if(strcmp (X.NAME1,Y.NAME1) <0)return 1; - Else return 0; - Else returnX.num > Y.num;//order from small to large in } - voidPrintintN) { to for(intI=0; i<n;i++){ +printf"%s%d\n", f[i].name,f[i].num); - } the } * intMain () $ {Panax Notoginseng intn,m; - while(SCANF ("%d", &n) &&N) { the for(intI=0; i<n;i++){ +scanf"%s%d",f[i].name,&f[i].num); A for(intj=0; J<=strlen (F[i].name); J + +) the if(f[i].name[j]>='A'&& f[i].name[j]<='Z') F[i].name1[j] = F[i].name[j] + +; + ElseF[I].NAME1[J] =F[i].name[j]; - } $Sort (f,f+n,cmd); $scanf"%d",&m); - print (n); - for(intI=0; i<m;i++){ the Charname[ -]; -scanf"%s", name);Wuyi //for (int i=0;i<strlen (name); i++) if (name[i]>= ' A ' && name[i]<= ' Z ') name[i] = Name[i] + +; the for(intj=0; j<n;j++){ - if(strcmp (name,f[j].name) = =0){ Wu - if(j>0&& f[j-1].num==f[j].num) { About intt=1; $ for(intk=j-1; k>=0; k--){ - if(F[k].num = = f[j].num) t++; - } -printf"%d%d", j-t+2, T); A +}Else{ theprintf"%d", j+1); - } $printf"\ n"); the } the } the } the } - return 0; in}
Song Jiang ' s rank list