考试排名 |
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
Total Submission(s): 2444 Accepted Submission(s): 864 |
Problem Description
C++编程考试使用的实时提交系统,具有即时获得成绩排名的特点。它的功能是怎么实现的呢?
我们做好了题目的解答,提交之后。要么“AC”,要么错误,无论如何错法,总是给你记上一笔,表明你以前有过一次错误提交,因而当你一旦提交该题“AC”后,就要与你算一算帐了,总共该题错误提交了几回。尽管你在题数上,大步地跃上了一个台阶,可是在耗时上要摊上你共花去的时间。特别是。以前有过的错误提交,每次都要摊上一定的单位时间分。这样一来,你在做出的题数上,可能率先别人非常多,可是。在做出相同题数的人群中,你可能会在耗时上处于排名的劣势。
|
Input
输入数据的第一行是考试题数n(1≤n≤12)以及单位罚分数m(10≤m≤20),每行数据描写叙述一个学生的username(不多于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 解析:这道题在杭电上属于简单题,可是做起来好麻烦。最恶心的就是格式问题了,只是涉及的东西还比較多,我认为不失为经典题哈!
#include <iostream> #include <string> #include <algorithm> #include <iomanip> using std::endl; using std::cin; using std::cout; using std::string; using std::sort; using std::setw; using std::ios; const int MAXN = 1000; struct student{ string name; int numSolved; int time; }stu[MAXN]; //处理字符串的函数 int strtoint(string s , int penaltyTime) { int value=0 , sum=0; for(int i=0; i<s.length(); ++i) { if(s[i]=='(') { sum+=value; value = 0; }else if(s[i]==')') { sum+=(value*penaltyTime); }else{ value=value*10+(s[i]-'0'); } } return sum > value ? sum:value; } //排序函数 bool cmp(student a , student b) { if(a.numSolved > b.numSolved) return true; if(a.numSolved == b.numSolved) return a.time < b.time; if(a.numSolved==b.numSolved && a.time == b.time) return a.name < b.name; return false; } int main() { #ifdef LOCAL freopen("input.txt" , "r" , stdin); #endif int n , penaltyTime; cin >> n >> penaltyTime; string name , str; int m = 0; //输入 while(cin >> name) { stu[m].name = name; for(int i=0; i<n; ++i) { cin >> str; if(str[0] >'0') { stu[m].numSolved++; stu[m].time += strtoint(str , penaltyTime); } } m++; } //排序 sort(stu , stu+m , cmp); //输出 for(int i=0; i<m; ++i) { //控制左对齐 cout.flags(ios::left); //控制占用字符 cout << setw(10) << stu[i].name << " "; //控制右对齐 cout.flags(ios::right); //控制字符和输出格式 cout << setw(2) << stu[i].numSolved << " "; cout << setw(4) << stu[i].time; cout << endl; } return 0; } |