HDU-2093 考试排名

题目

https://vjudge.net/problem/HDU-2093

题目大意

本题需要根据输入的每人每题得分数据对最终成绩进行排序,其中评分标准为:

  1. 负数代表提交错误次数,即本题未成功,不计入罚时;
  2. "a(b)"其中a、b均为正数,a表示提交正确时的时间,b表示之间提交错误过的次数,需计入罚时;
  3. 仅有一个正数表示提交正确的时间,且之前没有提交错误的情况。

对于有罚时的题目,需要用错误次数乘单位时间。最终先按每人完成题目排序,再按总时长由短到长排序。了解题意后便可以得到相应的排序方法。

解题思路

本题为一道模拟题,题目结合ACM赛制的评分与罚时规则。在输入时,可以统一用string来输入,这样也便于处理括号等情况。通过检测输入数据是否有负号,有负号的数据可以当做零处理。对于不带括号的数字,可以用string自带函数转化为数字类型,加入该选手总时长即可,同时需要给该选手完成题目数加一。对于带括号的数字,可以从"(“的位置将其划分为两段string,同时删去末尾的”)",再给总时长加上"a+b*单位时长",完成后同样给选手完成题目数加一。之后调用sort函数,根据题目排序要求写出cmp函数,按题目要求格式输出最终结果即可。

具体代码

#include <iostream> 
#include <cstdio> 
#include <fstream> 
#include <algorithm> 
#include <cmath> 
#include <deque> 
#include <vector> 
#include <queue> 
#include <string> 
#include <cstring> 
#include <map> 
#include <stack> 
#include <set> 
#include<cstdlib>
#include<ctime>
#include<iomanip>
#define ll long long
#define FOR(i,a,n) for(register int i=a;i<n;i++)
#define RF(i,a,n) for(register int i=a;i>n;i--)
#define NIL -1

using namespace std;

struct node{
	string name;
	int grade;
	int total;
}st[200];

bool cmp(struct node a, struct node b)
{
	if(a.total != b.total)
	{
		return a.total > b.total;
	}
	else if(a.grade != b.total)
	{
		return a.grade < b.grade;
	}
	else
	{
		return a.name + b.name < b.name + a.name;
	}
}

int main()
{
	int n,m,cnt = 0;
	cin >> n >> m;
	string temp;
	while(cin >> temp)
	{
		st[cnt].name = temp;
		st[cnt].grade = 0;
		st[cnt].total = 0;
		string tmp;
		for(int i = 0; i < n; i++)
		{
			cin >> tmp;
			if(tmp == "0")
			{
				continue;
			}
			if(tmp.find("(",0) != -1)
			{
				int s = tmp.find("(",0);
				int e = tmp.find(")",0);
				string aa = tmp.substr(s+1,e-s-1);
				string bb = tmp.substr(0,s);
				st[cnt].grade += atoi(aa.c_str()) * m;   //
				st[cnt].grade += atoi(bb.c_str());   //
				st[cnt].total++;
			}
			else
			{
				if(tmp.find("-",0) == -1)
				{
					st[cnt].grade += atoi(tmp.c_str());
					st[cnt].total++;
				}
			}
		}
		cnt++;
	} 
	sort(st,st+cnt-1,cmp);
	for(int i = 0; i < cnt; i++)
	{
		cout<<setiosflags(ios::left)<<setw(10)<<st[i].name;
		cout << " ";
		printf("%2d",st[i].total);
		cout << " ";
		printf("%4d",st[i].grade);
		cout << endl;
	}
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值