HDU1084-What Is Your Grade

HDU1084--What Is Your Grade?

What Is Your Grade?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8255    Accepted Submission(s): 2529


Problem Description
“Point, point, life of student!”
This is a ballad(歌谣)well known in colleges, and you must care about your score in this exam too. How many points can you get? Now, I told you the rules which are used in this course.
There are 5 problems in this final exam. And I will give you 100 points if you can solve all 5 problems; of course, it is fairly difficulty for many of you. If you can solve 4 problems, you can also get a high score 95 or 90 (you can get the former(前者) only when your rank is in the first half of all students who solve 4 problems). Analogically(以此类推), you can get 85、80、75、70、65、60. But you will not pass this exam if you solve nothing problem, and I will mark your score with 50.
Note, only 1 student will get the score 95 when 3 students have solved 4 problems.
I wish you all can pass the exam! 
Come on!
 

Input
Input contains multiple test cases. Each test case contains an integer N (1<=N<=100, the number of students) in a line first, and then N lines follow. Each line contains P (0<=P<=5 number of problems that have been solved) and T(consumed time). You can assume that all data are different when 0<p.
A test case starting with a negative integer terminates the input and this test case should not to be processed.
 

Output
Output the scores of N students in N lines for each case, and there is a blank line after each case.
 

Sample Input
4 5 06:30:17 4 07:31:27 4 08:12:12 4 05:23:13 1 5 06:30:17 -1
 

Sample Output
100 90 90 95 100
 
解析:这个题目中有点没有说清楚,当题目的数量只有一个人的时候给予的分数是少的。
贴一下自己的代码,代码写的很长,但是很清楚哈!
#include<iostream>
#include <string>
#include <algorithm>
using std::endl;
using std::cin;
using std::cout;
using std::string;
using std::sort;
const int MAXN = 100 + 10;
struct grade{
	//题目的数量
	int numSolved;
	//时间
	string time;
	//标号
	int flag;
	//存放最终的成绩
	int score;
}stu[MAXN];
//记录解决相同的题目数的人数
int count[6];
//首先按照题目数量降序,题目数相同时按照时间递增排序
bool cmp_1(grade a , grade b)
{
	if(a.numSolved > b.numSolved)
		return true;
	if(a.numSolved == b.numSolved)
		return (a.time < b.time);
	return false;
}
//按照标号进行排序
bool cmp_2(grade a , grade b)
{
	return a.flag < b.flag;
}
int main()
{
#ifdef LOCAL
	freopen("input.txt" , "r" , stdin);
#endif
	int N;
	while(cin >> N)
	{
		//重置
		memset(count , 0 ,sizeof count);
		if(N<0)
			break;
		//输入数据
		for(int i=0; i<N;++i)
		{
			cin >> stu[i].numSolved >> stu[i].time;
			stu[i].flag = i;
			count[stu[i].numSolved]++;
		}
		//排序
		sort(stu , stu+N , cmp_1);
		int cnt_2 = 0 , cnt_3 = 0 , cnt_4 = 0 ,cnt_1 = 0;
		//开始计算成绩
		for(int i=0; i<N;++i)
		{
			if(stu[i].numSolved == 0)
			{
				stu[i].score = 50;
			}
			if(stu[i].numSolved == 5)
			{
				stu[i].score = 100;
			}
			if(stu[i].numSolved == 4)
			{
				cnt_4++;
				if(cnt_4 <= count[4]/2)
				{
					stu[i].score = 95;
				}else{
					stu[i].score = 90;
				}
			}
			if(stu[i].numSolved == 3)
			{
				cnt_3++;
				if(cnt_3 <= count[3]/2)
				{
					stu[i].score = 85;
				}else{
					stu[i].score = 80;
				}
			}
			if(stu[i].numSolved == 2)
			{
				cnt_2++;
				if(cnt_2 <= count[2]/2)
				{
					stu[i].score = 75;
				}else{
					stu[i].score = 70;
				}
			}
			if(stu[i].numSolved == 1)
			{
				cnt_1++;
				if(cnt_1 <= count[1]/2)
				{
					stu[i].score = 65;
				}else{
					stu[i].score = 60;
				}
			}
		}
		//排序进行输出成绩
		sort(stu , stu+N , cmp_2);
		for(int i=0;i<N;++i)
		{
			cout << stu[i].score << endl;
		}
		cout << endl;
	}
	return 0;
}