5N - 考试排名
我们做好了题目的解答,提交之后,要么“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
#include<stdio.h>
#include<cstdio>
#include<string.h>
#include<algorithm>
using namespace std; struct Student
{ char name[]; int ac; int time; }; bool cmp(struct Student a, struct Student b)
{
if(a.ac!=b.ac) return a.ac>b.ac;
if(a.time!=b.time) return a.time<b.time;
return strcmp(a.name,b.name)<;
} int main()
{
int n,m, a,b, len;
struct Student st[], t;
char sta[];
scanf("%d %d", &n, &m);
// 处理输入数据
int i=;
while(scanf("%s", st[i].name)!=EOF)
{
st[i].ac=; st[i].time=;
for(int j=;j<n;j++)
{
scanf("%s", sta);
len=strlen(sta);
if(sta[]!='-')
{
st[i].ac++;
if(sta[len-]==')')
{
sscanf(sta, "%d(%d)", &a,&b);
st[i].time+=a+b*m;
}
else
{
sscanf(sta, "%d", &a);
if(a) st[i].time+=a;
else st[i].ac--;
}
}
}
// 判断是否为新人
for(int j=;j<i;j++)
if(strcmp(st[j].name,st[i].name)==)
{
st[j].ac=st[i].ac; st[j].time=st[i].time;
i--; break;
}
i++;
}
// 排序
sort(st,st+i,cmp);
// 数据输出
for(int j=;j<i;j++)
printf("%-10s %2d %4d\n", st[j].name, st[j].ac, st[j].time);
return ;
}
AC
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; struct Student
{ char name[]; int ac; int time; } st[]; bool cmp(Student a, Student b)
{
if(a.ac!=b.ac) return a.ac>b.ac; // 先按AC题数的多少排,多的在前
if(a.time!=b.time) return a.time<b.time; // 再按时间分的多少排,少的在前
return strcmp(a.name,b.name)<; // 如果凑巧前两者都相等,
} // 则按名字的字典序排,小的在前 int main()
{
int n,m, a,b, len;
scanf("%d %d", &n, &m);
// 处理输入数据
int i=;
while(scanf(" %s", st[i].name)!=EOF)
{
st[i].ac=; st[i].time=;
for(int j=;j<n;j++)
{
scanf("%d", &a);
if(a>)
{
st[i].ac++; st[i].time+=a;
if(getchar()=='(')
{
scanf("%d)", &b);
st[i].time+=b*m;
}
}
}
i++;
}
// 排序
sort(st,st+i,cmp);
// 数据输出
for(int j=;j<i;j++)
printf("%-10s %2d %4d\n", st[j].name, st[j].ac, st[j].time);
return ;
}
AC*2
5N - 考试排名的更多相关文章
- HDU——2093考试排名(string类及其函数的运用以及istringstream)
考试排名 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- HDOJ(HDU) 2093 考试排名(Arrays.sort排序、类的应用)
Problem Description C++编程考试使用的实时提交系统,具有即时获得成绩排名的特点.它的功能是怎么实现的呢? 我们做好了题目的解答,提交之后,要么"AC",要么错 ...
- B - 考试排名
C++编程考试使用的实时提交系统,具有即时获得成绩排名的特点.它的功能是怎么实现的呢? 我们做好了题目的解答,提交之后,要么"AC",要么错误,不管怎样错法,总是给你记上一笔,表明 ...
- HDU 2093 考试排名 模拟题
解题报告: 题目描述:写一个程序给一个编程考试C++实时提交系统排名,给你的数据是题目的总数,每次错误提交罚的时间分,每位用户的姓名,然后是输入用户每题的完成情况,有一下几种情况,第一,输入只有一个正 ...
- 题解报告:hdu 2093 考试排名
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2093 Problem Description C++编程考试使用的实时提交系统,具有即时获得成绩排名的 ...
- HD-ACM算法专攻系列(16)——考试排名
问题描述: 源码: 主要要注意输出格式. #include"iostream" #include"iomanip" #include"algorith ...
- ZJNU 1164 - 考试排名——中级
1.如果一个单元为0,表示没做过这题,不计入成绩 2.如果一个单位为负数,表示做错了这题,不计入成绩 所以只要一个单元为正数(不论是否有括号)都说明做出了这一题,计入成绩 将名字和成绩都当作字符串读入 ...
- hdu2093 考试排名(还需完善)
下面代码是借鉴的.好多的知识点等着完善 #include <iostream> #include <string> #include <algorithm> usi ...
- HDU2093--考试排名
考试排名 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissi ...
随机推荐
- 使用nodeValue获取值与a标签默认跳转的冲突问题
今天看javascript DOM编程艺术(第2版)发现这样一个例子: 效果图: 完整代码: <!DOCTYPE html> <html lang="en"> ...
- redis-大key寻找
使用redis-rdb-tools 项目地址 https://github.com/sripathikrishnan/redis-rdb-tools 生成csv命令 rdb -c memory //d ...
- leetcode每日刷题计划-简单篇day13
Num 169 先码,回头再说,摩尔算法... tle了 class Solution { public: int majorityElement(vector<int>& num ...
- LeetCode 112. Path Sum 二叉树的路径和 C++
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...
- tornado架构分析2 options.py实现原理
总结体会: options这个文件是用来管理程序运行过程中配置的,它采用了单例模式,整个程序运行时只有一个实例存在. 参数可以从命令行读取,也可以从配置文件中读取,就看你怎么用了. 同时,option ...
- 使用samba 共享Linux文件到Windows
1.使用yum命令安装了samba服务 #yum install samba 2.配置/etc/samba/smb.conf文件,在最后一行添加下面一段配置: #vi /etc/samba/smb.c ...
- Jmeter学习记录
JSON正则表达式提取规则 https://www.cnblogs.com/hc1020/p/7723720.html Jmeter非GUI下执行日志 执行命令 ./jmeter -n -t $ ...
- 4.Linux开机设置项
开机建议优化项: //关闭防火墙 systemctl stop firewalld systemctl disable firewalld //关闭SELinux: setenforce 0 sed ...
- ZigZag Conversion 之字形转换字符串
1.题目 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows ...
- week05 codelab01 Babel ES6 webpack Nodejsserver等
Babel 他出现的原因就是很多浏览器还未完全兼容ES6 需要将你写的ES6的内容转换成ES5让浏览器兼容运行 ES5和ES6相比出现很多新内容 比如拼接字符串 ES6可以` ` 里面如果引用变量就用 ...