5N - 考试排名

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 

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

// WA*10
不说了代码省略
// int sscanf ( const char * s, const char * format, ...);  <cstdio>
// Reads data from s and stores them according to parameter format into the locations given by the additional arguments,
// as if scanf was used, but reading from s instead of the standard input (stdin).
// 多条件排序使用sort+bool
 1 #include<stdio.h>
 2 #include<cstdio>
 3 #include<string.h>
 4 #include<algorithm>
 5 using namespace std;
 6 
 7 struct Student
 8 { char name[11]; int ac; int time; };
 9 
10 bool cmp(struct Student a, struct Student b)
11 {
12     if(a.ac!=b.ac) return a.ac>b.ac;            
13     if(a.time!=b.time) return a.time<b.time;    
14     return strcmp(a.name,b.name)<0;            
15 }                                            
16 
17 int main()
18 {
19     int n,m, a,b, len;
20     struct Student st[1000], t;
21     char sta[10];
22     scanf("%d %d", &n, &m);
23     // 处理输入数据 
24     int i=0;
25     while(scanf("%s", st[i].name)!=EOF)
26     {
27         st[i].ac=0; st[i].time=0;
28         for(int j=0;j<n;j++)
29         {
30             scanf("%s", sta);
31             len=strlen(sta);
32             if(sta[0]!='-')
33             {
34                 st[i].ac++;
35                 if(sta[len-1]==')')
36                 {
37                     sscanf(sta, "%d(%d)", &a,&b);
38                     st[i].time+=a+b*m;
39                 }
40                 else
41                 {
42                     sscanf(sta, "%d", &a);
43                     if(a) st[i].time+=a;
44                     else st[i].ac--;
45                 }
46             }
47         }
48         // 判断是否为新人
49         for(int j=0;j<i;j++)
50             if(strcmp(st[j].name,st[i].name)==0)
51             {
52                 st[j].ac=st[i].ac; st[j].time=st[i].time;
53                 i--; break;
54             }
55         i++;
56     }
57     // 排序
58     sort(st,st+i,cmp);
59     // 数据输出 
60     for(int j=0;j<i;j++)
61         printf("%-10s %2d %4d\n", st[j].name, st[j].ac, st[j].time);
62     return 0;
63 }
AC
 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<algorithm>
 4 using namespace std;
 5 
 6 struct Student
 7 { char name[11]; int ac; int time; } st[10000];
 8 
 9 bool cmp(Student a, Student b)
10 {
11     if(a.ac!=b.ac) return a.ac>b.ac;            // 先按AC题数的多少排,多的在前
12     if(a.time!=b.time) return a.time<b.time;    // 再按时间分的多少排,少的在前
13     return strcmp(a.name,b.name)<0;                // 如果凑巧前两者都相等,
14 }                                                // 则按名字的字典序排,小的在前
15 
16 int main()
17 {
18     int n,m, a,b, len;
19     scanf("%d %d", &n, &m);
20     // 处理输入数据 
21     int i=0;
22     while(scanf(" %s", st[i].name)!=EOF)
23     {
24         st[i].ac=0; st[i].time=0;
25         for(int j=0;j<n;j++)
26         {
27             scanf("%d", &a);
28             if(a>0)
29             {
30                 st[i].ac++; st[i].time+=a;
31                 if(getchar()=='(')
32                 {
33                     scanf("%d)", &b);
34                     st[i].time+=b*m;
35                 }
36             }
37         }
38         i++; 
39     }
40     // 排序
41     sort(st,st+i,cmp);
42     // 数据输出 
43     for(int j=0;j<i;j++)
44         printf("%-10s %2d %4d\n", st[j].name, st[j].ac, st[j].time);
45     return 0;
46 }
AC*2

猜你喜欢

转载自www.cnblogs.com/goldenretriever/p/10363373.html