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 ...
随机推荐
- css3中transform的用法
transform:rotate旋转deg #box1{ -moz-transform:rotate(10deg); -webkit-transform:rotate(10deg); }transfo ...
- Boostrap(1)
1.简介 Bootstrap 是一个用于快速开发 Web 应用程序和网站的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,可以认为bootstrap就是一个样式库. ...
- java中的File类
File类 java中的File类其实和文件并没有多大关系,它更像一个对文件路径描述的类.它即可以代表某个路径下的特定文件,也可以用来表示该路径的下的所有文件,所以我们不要被它的表象所迷惑.对文件的真 ...
- 深入理解C#泛型
前面两篇文章介绍了C#泛型的基本知识和特性,下面我们看看泛型是怎么工作的,了解一下泛型内部机制. 泛型内部机制 泛型拥有类型参数,通过类型参数可以提供"参数化"的类型,事实上,泛型 ...
- AngularJs-MVC之路由、模块以及依赖注入
前面呢,我们大概的了解了下AngularJs的入门,也做过了hello world的一个demo,不知道大家有没有掌握呢?在下面我们需要讲一些AngularJS的一些干货. 1,一个完整项目的目录结构 ...
- iOS开发之UITextView,设置textView的行间距及placeholder
一.设置textView的行间距 1.如果只是静态显示textView的内容为设置的行间距,执行如下代码: // textview 改变字体的行间距 NSMutableParagraph ...
- python 中转义字符的注释
文章转自:http://blog.sina.com.cn/s/blog_89e141170101cs73.html 转义字符 描述 \(在行尾时) 续行符 \\ 反斜杠符号 \’ 单引号 \” 双引号 ...
- 【转】变量的声明和定义,从C到编译原理到C++,再到Java
基础学了太久,时间一长有些东西就可能记得不太清楚,俗话说得好,"好记性不如烂笔头",所以把基础中的基础-变量的声明和定义,从C到编译原理到C++,再到Java用烂笔头记录下来 最早 ...
- if...else语句的应用题
应用题 namespace ConsoleApplication1 { /* 题目要求:提示用户输入年龄,如果大于等于18,那么用户可以查看.如果小于10岁,则告知用户”少儿不宜“. 如果大于等于10 ...
- Linux使用
RedHat5 [cat] 将一个文件内容加入到另外一个另外一个文件中 参数 -n 或 --number 由 1 开始对所有输出的行数编号 -b 或 --number-nonblank 和 -n 相似 ...