1084HDU

题目很好理解,就是一道简单的排序题
当然,如果只有1个人完成了4道题,下面的代码仍然会输出90分,代码依然会ac,可能是题目的测试数据太水的缘故,可以自己修改

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
class Student {
	public:
		string time;//完成题目的时间
		int sloved;//解决的题目的数量
		int index;//次序
		int point;//得分
		static int one_sloved;//解决了一道题目的学生的数量
		static int two_sloved;//解决了两道题目的学生的数量
		static int three_sloved;//解决了三道题目的学生的数量
		static int four_sloved;//解决了四道题目的学生的数量
};
int Student::one_sloved=0;
int Student::two_sloved=0;
int Student::three_sloved=0;
int Student::four_sloved=0;
bool Com1(Student&s1,Student&s2) {
	if(s1.sloved!=s2.sloved)return s1.sloved>s2.sloved;
	else if(s1.sloved==s2.sloved)return s1.time<s2.time;
}
bool Com2(Student&s1,Student&s2)
{
	return s1.index<s2.index;
}
int main() {
	int t;
	while(cin>>t&&t>=0) {
		vector<Student> stu;
		for(int i=0; i<t; i++) {
			Student s;
			cin>>s.sloved>>s.time;
			s.index=i;
			switch(s.sloved) {
				case 1:
					Student::one_sloved++;
					break;
				case 2:
					Student::two_sloved++;
					break;
				case 3:
					Student::three_sloved++;
					break;
				case 4:
					Student::four_sloved++;
					break;
				default:
					break;
			}
			stu.push_back(s);
		}
		sort(stu.begin(),stu.end(),Com1);
		Student::one_sloved/=2;
		Student::two_sloved/=2;
		Student::three_sloved/=2;
		Student::four_sloved/=2;
		//进行打分
		for(vector<Student>::iterator it=stu.begin(); it!=stu.end(); it++) {
			switch(it->sloved) {
				case 0:
					it->point=50;
					break;
				case 1:
					if(Student::one_sloved) {
						Student::one_sloved--;
						it->point=65;
					} else it->point=60;
					break;
				case 2:
					if(Student::two_sloved) {
						Student::two_sloved--;
						it->point=75;
					} else it->point=70;
					break;
				case 3:
					if(Student::three_sloved) {
						Student::three_sloved--;
						it->point=85;
					} else it->point=80;
					break;
				case 4:
					if(Student::four_sloved) {
						Student::four_sloved--;
						it->point=95;
					} else it->point=90;
					break;
				case 5:
					it->point=100;
					break;

			}
		}
		//按次序重新排序,然后输出
		sort(stu.begin(),stu.end(),Com2);
		for(vector<Student>::iterator it=stu.begin(); it!=stu.end(); it++)
		{
			cout<<it->point<<endl;
		}
		cout<<endl;
	}

	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值