Song Jiang's rank list
Time Limit:1000MS Memory Limit:512000KB 64bit IO Format:%I64d & %I64u
Description
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
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
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
Sample Output
#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的更多相关文章
- 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 ...
- 2014ACM/ICPC亚洲区广州站 Song Jiang's rank list
欢迎参加——每周六晚的BestCoder(有米!) Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- 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 ...
- 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 ...
- UVALive 7077 - Song Jiang's rank list(模拟)
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- 【HDOJ】5131 Song Jiang's rank list
STL的使用. /* 5131 */ #include <iostream> #include <map> #include <cstdio> #include & ...
- UVA, 10336 Rank the Languages
难点在于:递归函数和输出: #include <iostream> #include <vector> #include <algorithm> #include ...
- [LeetCode] Rank Scores 分数排行
Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...
- rank()函数的使用
排序: ---rank()over(order by 列名 排序)的结果是不连续的,如果有4个人,其中有3个是并列第1名,那么最后的排序结果结果如:1 1 1 4select scoreid, stu ...
随机推荐
- C#爬页面总结
错误的思路是这样的:发送一个访问页面的请求过去,得到一个html页面,然后我要的数据全都在这上面.后来发现不是这样的,也猜到可能是页面加载之后还有js代码的ajax的异步加载,那么问题来了?我是不是要 ...
- Zigbee技术特点
ZigBee工作原理 基于 ZigBee 的无线设备工作在 868MHZ, 915MHZ 和 2.4Z 频带.其最大数据速 率是 250Kbps. ZigBee 技术主要针对以电池为电源的应用,这些应 ...
- jQuery找兄弟系列next(),nextAll(),nextUntil(),prev(),prevAll(),prevUntil(),siblings()
<body> <div id="main"> <div id="hot" class="rightbar"&g ...
- [wikioi1553]互斥的数(数学分析+散列/数学分析+二分)
题目描述 Description 有这样的一个集合,集合中的元素个数由给定的N决定,集合的元素为N个不同的正整数,一旦集合中的两个数x,y满足y = P*x,那么就认为x,y这两个数是互斥的,现在想知 ...
- 深入理解C#泛型
前面两篇文章介绍了C#泛型的基本知识和特性,下面我们看看泛型是怎么工作的,了解一下泛型内部机制. 泛型内部机制 泛型拥有类型参数,通过类型参数可以提供"参数化"的类型,事实上,泛型 ...
- codeforces 359D 二分答案+RMQ
上学期刷过裸的RMQ模板题,不过那时候一直不理解>_< 其实RMQ很简单: 设f[i][j]表示从i开始的,长度为2^j的一段元素中的最小值or最大值 那么f[i][j]=min/max{ ...
- android 读取sd卡中的图片
一.获取读取SD卡的权限 <!--在SDCard中创建与删除文件权限 --> <uses-permission android:name="android.perm ...
- Stream Byte[] 转换
public byte[] StreamToBytes(Stream stream) { byte[] bytes = new byte[stream.Length]; stream.Read(byt ...
- Effective Java之最佳建议
#Effective Java之最佳建议 此书中,目前给我帮助最大的两条建议是: - 检查参数的有效性 - 不要忽略异常 ###检查参数的有效性 对于这一条,使我感同身受的原因是:在Web项目中,前期 ...
- 用Nikto探测一个网站所用到的技术
Nikto是一款开源的(GPL)网页服务器扫描器,它可以对网页服务器进行全面的多种扫描,包含超过3300种有潜在危险的文件/CGIs:超过 625种服务器版本:超过230种特定服务器问题,包括多种有潜 ...