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 ...
随机推荐
- 记一次w3wp占用CPU过高的解决过程(Dictionary和线程安全)
项目上线以来一直存在一个比较揪心的问题,和一个没有信心处理的BUG,那就是在应用程序启动时有可能会导致cpu跑满99%或持续在一个值如50%左右,这样一来对服务器的压力是非常大的,经常出现服务器无法远 ...
- 第一个C语言编译器是怎样编写的?
首先向C语言之父Dennis MacAlistair Ritchie致敬! 当今几乎所有的实用的编译器/解释器(以下统称编译器)都是用C语言编写的,有一些语言比如Clojure,Jython等是基于J ...
- HTML5——地图应用
我们就拿百度地图举例吧: 废话少说,直接上Demo 简要截图如下:' 简要代码如下: <!DOCTYPE html> <html> <head> <title ...
- hdu1828 线段树+离散化+扫描线
添加lb[],rb[]数组,来标记竖边.添加num,来计算竖边的个数,因为计算周长的时候,未覆盖的竖边都要加. #include<stdio.h> #include<stdlib.h ...
- js常用插件
1.jQuery Shortcuts 是个超轻量级的方法,使用 jQuery 来绑定快捷键(热键). 2.Underscore封装了常用的JavaScript对象操作方法,用于提高开发效率. 3.Kn ...
- tarjan算法--求无向图的割点和桥
一.基本概念 1.桥:是存在于无向图中的这样的一条边,如果去掉这一条边,那么整张无向图会分为两部分,这样的一条边称为桥无向连通图中,如果删除某边后,图变成不连通,则称该边为桥. 2.割点:无向连通图中 ...
- 【CodeForces 613B】Skills
题 题意 给你n个数,可以花费1使得数字+1,最大加到A,最多花费m.最后,n个数里的最小值为min,为A的有k个,给你cm和cf,求force=min*cm+k*cf 的最大值,和n个数操作后的结果 ...
- Hibernate中一级缓存和二级缓存使用详解
一.一级缓存二级缓存的概念解释 (1)一级缓存就是Session级别的缓存,一个Session做了一个查询操作,它会把这个操作的结果放在一级缓存中,如果短时间内这个 session(一定要同一个ses ...
- Java编程思想学习(八) 内部类
可以将一个类的定义放在另一个类的定义内部,这就是内部类. 内部类的定义是简单的,但是它的语法确实很是复杂,让人不是很好理解.下面就内部类做一个小结. 一.内部类的分类 总的来讲内部类分为普通内部类,匿 ...
- linux 破解版confluence安装
OS centos 6.5 需要的安装包如下: jre-7u67-linux-x64.rpm atlassian-confluence-5.4.4-x64.bin mysql-connector- ...