码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 1718 Rank

时间:2015-06-09 16:50:45      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=1718 

Rank

Description

Jackson wants to know his rank in the class. The professor has posted a list of student numbers and marks. Compute Jackson’s rank in class; that is, if he has the top mark(or is tied for the top mark) his rank is 1; if he has the second best mark(or is tied) his rank is 2, and so on.

Input

The input consist of several test cases. Each case begins with the student number of Jackson, an integer between 10000000 and 99999999. Following the student number are several lines, each containing a student number between 10000000 and 99999999 and a mark between 0 and 100. A line with a student number and mark of 0 terminates each test case. There are no more than 1000 students in the class, and each has a unique student number.

Output

For each test case, output a line giving Jackson’s rank in the class.

Sample Input

20070101
20070102 100
20070101 33
20070103 22
20070106 33
0 0

Sample Output

2

stl大法好。。

技术分享
 1 #include<algorithm>
 2 #include<iostream>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<map>
 7 using std::map;
 8 map<int, int> rec;
 9 int main() {
10 #ifdef LOCAL
11     freopen("in.txt", "r", stdin);
12     freopen("out.txt", "w+", stdout);
13 #endif
14     int num, id, score, rank, targe;
15     while (~scanf("%d", &num)) {
16         rank = 0, rec.clear();
17         while (~scanf("%d %d", &id, &score) && id + score) rec[id] = score;
18         targe = rec[num];
19         map<int, int>::iterator ite;
20         for (ite = rec.begin(); ite != rec.end(); ++ite) {
21             if (ite->second > targe) rank++;
22         }
23         printf("%d\n", rank + 1);
24     }
25     return 0;
26 }
View Code

 

hdu 1718 Rank

标签:

原文地址:http://www.cnblogs.com/GadyPu/p/4563512.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!