Problem Description
C++编程考试使用的实时提交系统,具有即时获得成绩排名的特点。它的功能是怎么实现的呢?
我们做好了题目的解答,提交之后,要么“AC”,要么错误,不管怎样错法,总是给你记上一笔,表明你曾经有过一次错误提交,因而当你一旦提交该题“AC”后,就要与你算一算帐了,总共该题错误提交了几回。虽然你在题数上,大步地跃上了一个台阶,但是在耗时上要摊上你共花去的时间。特别是,曾经有过的错误提交,每次都要摊上一定的单位时间分。这样一来,你在做出的题数上,可能领先别人很多,但是,在做出同样题数的人群中,你可能会在耗时上处于排名的劣势。
例如:某次考试一共8题(A,B,C,D,E,F,G,H),每个人做的题都在对应的题号下有个数量标记,负数表示该学生在该题上有过的错误提交次数,但到现在还没有AC,正数表示AC所耗的时间,如果正数a跟上一对括号,里面有个整数b,那就表示该学生提交该题AC了,耗去了时间a,同时,曾经错误提交了b次,因此对于下述输入数据:
若每次错误提交的罚分为20分,则其排名从高到低应该是这样的:
Josephus 5 376
John 4 284
Alice 4 352
Smith 3 167
Bob 2 325
Bush 0 0
我们做好了题目的解答,提交之后,要么“AC”,要么错误,不管怎样错法,总是给你记上一笔,表明你曾经有过一次错误提交,因而当你一旦提交该题“AC”后,就要与你算一算帐了,总共该题错误提交了几回。虽然你在题数上,大步地跃上了一个台阶,但是在耗时上要摊上你共花去的时间。特别是,曾经有过的错误提交,每次都要摊上一定的单位时间分。这样一来,你在做出的题数上,可能领先别人很多,但是,在做出同样题数的人群中,你可能会在耗时上处于排名的劣势。
例如:某次考试一共8题(A,B,C,D,E,F,G,H),每个人做的题都在对应的题号下有个数量标记,负数表示该学生在该题上有过的错误提交次数,但到现在还没有AC,正数表示AC所耗的时间,如果正数a跟上一对括号,里面有个整数b,那就表示该学生提交该题AC了,耗去了时间a,同时,曾经错误提交了b次,因此对于下述输入数据:
![](https://i-blog.csdnimg.cn/blog_migrate/e5c680689e03cd8254ae7e912272956b.png)
若每次错误提交的罚分为20分,则其排名从高到低应该是这样的:
Josephus 5 376
John 4 284
Alice 4 352
Smith 3 167
Bob 2 325
Bush 0 0
Input
输入数据的第一行是考试题数n(1≤n≤12)以及单位罚分数m(10≤m≤20),每行数据描述一个学生的用户名(不多于10个字符的字串)以及对所有n道题的答题现状,其描述采用问题描述中的数量标记的格式,见上面的表格,提交次数总是小于100,AC所耗时间总是小于1000。
Output
将这些学生的考试现状,输出一个实时排名。实时排名显然先按AC题数的多少排,多的在前,再按时间分的多少排,少的在前,如果凑巧前两者都相等,则按名字的字典序排,小的在前。每个学生占一行,输出名字(10个字符宽),做出的题数(2个字符宽,右对齐)和时间分(4个字符宽,右对齐)。名字、题数和时间分相互之间有一个空格。
Sample Input
8 20 Smith -1 -16 8 0 0 120 39 0 John 116 -2 11 0 0 82 55(1) 0 Josephus 72(3) 126 10 -3 0 47 21(2) -2 Bush 0 -1 -8 0 0 0 0 0 Alice -2 67(2) 13 -1 0 133 79(1) -1 Bob 0 0 57(5) 0 0 168 -7 0
Sample Output
Josephus 5 376 John 4 284 Alice 4 352 Smith 3 167 Bob 2 325 Bush 0 0
![可怜](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cute.gif)
![可怜](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cute.gif)
![可怜](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cute.gif)
![可怜](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cute.gif)
![可怜](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cute.gif)
![可怜](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cute.gif)
![惊恐](http://static.blog.csdn.net/xheditor/xheditor_emot/default/panic.gif)
![惊恐](http://static.blog.csdn.net/xheditor/xheditor_emot/default/panic.gif)
![鄙视](http://static.blog.csdn.net/xheditor/xheditor_emot/default/despise.gif)
![鄙视](http://static.blog.csdn.net/xheditor/xheditor_emot/default/despise.gif)
![鄙视](http://static.blog.csdn.net/xheditor/xheditor_emot/default/despise.gif)
![鄙视](http://static.blog.csdn.net/xheditor/xheditor_emot/default/despise.gif)
![鄙视](http://static.blog.csdn.net/xheditor/xheditor_emot/default/despise.gif)
![鄙视](http://static.blog.csdn.net/xheditor/xheditor_emot/default/despise.gif)
![鄙视](http://static.blog.csdn.net/xheditor/xheditor_emot/default/despise.gif)
![鄙视](http://static.blog.csdn.net/xheditor/xheditor_emot/default/despise.gif)
![鄙视](http://static.blog.csdn.net/xheditor/xheditor_emot/default/despise.gif)
![鄙视](http://static.blog.csdn.net/xheditor/xheditor_emot/default/despise.gif)
while (scanf("%s %c %c", str, &oldchar, &newchar) == 3) /* 或!= EOF , 但前者更好 */
{
; //处理
}
![鄙视](http://static.blog.csdn.net/xheditor/xheditor_emot/default/despise.gif)
![鄙视](http://static.blog.csdn.net/xheditor/xheditor_emot/default/despise.gif)
![可怜](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cute.gif)
![羡慕](http://static.blog.csdn.net/xheditor/xheditor_emot/default/envy.gif)
![可怜](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cute.gif)
![羡慕](http://static.blog.csdn.net/xheditor/xheditor_emot/default/envy.gif)
![可怜](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cute.gif)
![可怜](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cute.gif)
![可怜](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cute.gif)
![可怜](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cute.gif)
![可怜](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cute.gif)
![可怜](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cute.gif)
![奋斗](http://static.blog.csdn.net/xheditor/xheditor_emot/default/struggle.gif)
![奋斗](http://static.blog.csdn.net/xheditor/xheditor_emot/default/struggle.gif)
![再见](http://static.blog.csdn.net/xheditor/xheditor_emot/default/bye.gif)
![再见](http://static.blog.csdn.net/xheditor/xheditor_emot/default/bye.gif)
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include<iomanip>
using namespace std;
#define SIZE 1000
typedef struct _score_info
{
string name;
int ac_num; //接受了的题目的数目
int time_score; //时间分
}S_INFO;
S_INFO info[SIZE];
string score[12];
int num_of_question;//问题的数目
int num;//每次罚的分数
bool cmp(const S_INFO &l, const S_INFO &r)
{
if (l.ac_num == r.ac_num)
{
if (l.time_score == r.time_score)
{
return l.name < r.name; //小的在前
}
else
return l.time_score < r.time_score; //按照时间分来排序,小的在前
}
else
{
return l.ac_num > r.ac_num; //按照题目数目来排序,大的在前面
}
}
void fill_info(int index)
{//解析字符,得到信息
int sum = 0; //得到的时间总分
int count = 0; //解决的题目数
for (int i = 0; i < num_of_question; ++i)
{
string::size_type str_index = score[i].find('('); //找到下标
if (str_index != string::npos)
{
count++;
string substr = score[i].substr(0, str_index);
sum += atoi(substr.c_str());
substr = score[i].substr(str_index + 1, score[i].length() - (str_index + 2));
sum += atoi(substr.c_str()) * num;
}
else
{
int temp = atoi(score[i].c_str());
if (temp > 0)
{
sum += temp;
count++;
}
}
}
info[index].ac_num = count;
info[index].time_score = sum;
}
int main()
{
cin >> num_of_question >> num;
int index = 0;
while(cin >> info[index].name)
{
int sum = 0; //得到的时间总分
int count = 0; //解决的题目数
info[index].ac_num = info[index].time_score = 0;
for (int j = 0; j < num_of_question; ++j)
{
cin >> score[j];
string::size_type str_index = score[j].find('('); //找到下标
if (str_index != string::npos) //找到了
{
count++;
string substr = score[j].substr(0, str_index);
sum += atoi(substr.c_str());
substr = score[j].substr(str_index + 1, score[j].length() - (str_index + 2));
sum += atoi(substr.c_str()) * num;
}
else //没找到
{
int temp = atoi(score[j].c_str());
if (temp > 0)
{
sum += temp;
count++;
}
}
}
info[index].ac_num = count;
info[index].time_score = sum;
index++;
}
sort(info, info + index, cmp);
for (int j = 0; j < index; ++j)
{
//printf("%-10s %2d %4d\n", info[j].name.c_str(), info[j].ac_num, info[j].time_score);
cout.flags(ios::left);
cout << setw(10) <<info[j].name;
cout << " " << setiosflags(ios::right) << setw(2) << info[j].ac_num;
cout << " " << setiosflags(ios::right) << setw(4) << info[j].time_score;
cout << endl;
}
system("pause");
return 0;
}