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

 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct st
{
char name[];
int kill;
}data[];
int cmp(st a,st b)//注意排序就好。
{
if(a.kill!=b.kill)
return a.kill > b.kill ;
else if(strcmp(a.name,b.name)<)
return ;
else
return ;
}
int main()
{
// freopen("a.txt" , "r" , stdin ) ;
int i,j,l,n,m,k,t;
char s[];
while(scanf("%d",&n)&&n)
{
for(i=;i<n;i++)
scanf("%s %d",data[i].name,&data[i].kill); sort(data,data+n,cmp); for(i=;i<n;i++)
{
printf("%s %d\n",data[i].name,data[i].kill);
}
scanf("%d",&m);
for(i=;i<m;i++)
{
scanf("%s",s);
for(l=;l<n;l++)
{
if(strcmp(s,data[l].name)==)
{
k=l;
t=;
for(j=k-;j>=;j--)
{
if(data[k].kill==data[j].kill)
t++;
}
if(t==)
printf("%d\n",k+);
else
printf("%d %d\n",k-t+,t);
}
}
}
}
return ;
}

sort(a , a+n, cmp)

Song Jiang's rank list的更多相关文章

  1. hdu 5131 Song Jiang's rank list

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5131 Song Jiang's rank list Description <Shui Hu Z ...

  2. 2014ACM/ICPC亚洲区广州站 Song Jiang's rank list

    欢迎参加——每周六晚的BestCoder(有米!) Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others)    Memory Li ...

  3. HDU5131-Song Jiang's rank list HDU5135-Little Zu Chongzhi's Triangles(大佬写的)

    Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java ...

  4. HDU 5131.Song Jiang's rank list (2014ACM/ICPC亚洲区广州站-重现赛)

    Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java ...

  5. UVALive 7077 - Song Jiang's rank list(模拟)

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  6. 【HDOJ】5131 Song Jiang's rank list

    STL的使用. /* 5131 */ #include <iostream> #include <map> #include <cstdio> #include & ...

  7. UVA, 10336 Rank the Languages

    难点在于:递归函数和输出: #include <iostream> #include <vector> #include <algorithm> #include ...

  8. [LeetCode] Rank Scores 分数排行

    Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...

  9. rank()函数的使用

    排序: ---rank()over(order by 列名 排序)的结果是不连续的,如果有4个人,其中有3个是并列第1名,那么最后的排序结果结果如:1 1 1 4select scoreid, stu ...

随机推荐

  1. 封印术:shadow dom

    置顶文章:<纯CSS打造银色MacBook Air(完整版)> 上一篇:<鼠标滚动插件smoovejs和wowjs> 作者主页:myvin 博主QQ:851399101(点击Q ...

  2. IT男的”幸福”生活"续1

    IT男的”幸福”生活"续1 我和LL开始下步追妹计划...... 知彼知已,方能把握机会.没想到孙子兵法太给力了,据LL了解,MM(她)是湖北人,找对象一般不会考虑外省的.高度165左右,相 ...

  3. [软件测试]Linux环境中简单清爽的Google Test (GTest)测试环境搭建(初级使用)

    本文将介绍单元测试工具google test(GTEST)在linux操作系统中测试环境的搭建方法.本文属于google test使用的基础教程.在linux中使用google test之前,需要对如 ...

  4. 记录我开始学习 Git的路程

    工作半年多了,总觉得没学到什么东西,于是乎找了个Git学习一下,感觉还蛮厉害的样子.为此记录下我的路程 2015,11,26 更新 前面的路都挺艰难的,在官网下载msysgit网速几乎为0(心情千万只 ...

  5. 第三十三课:jQuery Deferred详解1

    之前我们讲了Mochikit Deferred,JSDeferred,现在讲jQuery Deferred.首先,我们先来讲下他们的区别: 在保存回调函数时,Mochikit Deferred(doj ...

  6. Javascript基础系列之(四)数据类型 (数组 array)

    字符串,数值,布尔值都属于离散值(scalar),如果某个变量是离散的,那么任何时候它只有一个值. 如果想使用变量存储一组值,就需要使用数组(array). 数组是由多个名称相同的树值构成的集合,集合 ...

  7. VMware v12.1.1 专业版以及永久密钥

    热门虚拟机软件VMware Workstation 现已更新至v12.1.1 专业版!12.0属于大型更新,专门为Win10的安装和使用做了优化,支持DX10.4K高分辨率显示屏.OpenGL 3.3 ...

  8. 阿里百川IMSDK--自定义群聊界面

    // 获取群对象 YWTribe *tribe = [self.tribesArray objectAtIndex:indexPath.row]; // 发起群聊 UIViewController * ...

  9. 每天一个linux命令(48):netstat命令

    netstat命令用于显示与IP.TCP.UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况.netstat是在内核中访问网络及相关信息的程序,它能提供TCP连接,TCP和UDP ...

  10. dell r710 服务器配置RAID5(3块硬盘做RAID5,另外再弄一块做数据冗余盘)

    本文完全转载于:http://www.jb51.net/article/53814.htm,只为做笔记使用 ①4块硬盘做成RAID5 ②3块硬盘做RAID5,一块硬盘做热备盘 这两种配置之间的区别.大 ...