PAT A1137 Final Grading (25 分)——排序
For a student taking the online course "Data Structures" on China University MOOC (http://www.icourse163.org/), to be qualified for a certificate, he/she must first obtain no less than 200 points from the online programming assignments, and then receive a final grade no less than 60 out of 100. The final grade is calculated by G=(Gmid−term×40%+Gfinal×60%) if Gmid−term>Gfinal, or Gfinal will be taken as the final grade G. Here Gmid−term and Gfinal are the student's scores of the mid-term and the final exams, respectively.
The problem is that different exams have different grading sheets. Your job is to write a program to merge all the grading sheets into one.
Input Specification:
Each input file contains one test case. For each case, the first line gives three positive integers: P , the number of students having done the online programming assignments; M, the number of students on the mid-term list; and N, the number of students on the final exam list. All the numbers are no more than 10,000.
Then three blocks follow. The first block contains P online programming scores Gp's; the second one contains M mid-term scores Gmid−term's; and the last one contains N final exam scores Gfinal's. Each score occupies a line with the format: StudentID Score
, where StudentID
is a string of no more than 20 English letters and digits, and Score
is a nonnegative integer (the maximum score of the online programming is 900, and that of the mid-term and final exams is 100).
Output Specification:
For each case, print the list of students who are qualified for certificates. Each student occupies a line with the format:
StudentID
Gp Gmid−term Gfinal G
If some score does not exist, output "−1" instead. The output must be sorted in descending order of their final grades (G must be rounded up to an integer). If there is a tie, output in ascending order of their StudentID
's. It is guaranteed that the StudentID
's are all distinct, and there is at least one qullified student.
Sample Input:
6 6 7
01234 880
a1903 199
ydjh2 200
wehu8 300
dx86w 220
missing 400
ydhfu77 99
wehu8 55
ydjh2 98
dx86w 88
a1903 86
01234 39
ydhfu77 88
a1903 66
01234 58
wehu8 84
ydjh2 82
missing 99
dx86w 81
Sample Output:
missing 400 -1 99 99
ydjh2 200 98 82 88
dx86w 220 88 81 84
wehu8 300 55 84 84
#include <stdio.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string.h>
using namespace std;
const int maxn=;
struct stu{
int gp=-;
int gm=-;
int gf=-;
int g=;
string id;
bool qua=true;
}students[maxn];
int p,m,n,score;
string id;
int num=;
map<string,int> s2n;
map<int,string> n2s;
int string2num(string s){
if(s2n.find(s)==s2n.end()){
s2n[s]=num;
return num++;
}
else{
return s2n[s];
}
}
bool cmp(stu s1,stu s2){
return s1.g==s2.g?s1.id<s2.id:s1.g>s2.g;
}
int main(){
scanf("%d %d %d",&p,&m,&n);
for(int i=;i<p;i++){
cin>>id>>score;
if(score>) continue;
int index=string2num(id);
if(n2s.find(index)==n2s.end()){
n2s[index]=id;
students[index].id=id;
}
students[index].gp=score;
}
for(int i=;i<m;i++){
cin>>id>>score;
if(score>) continue;
int index=string2num(id);
if(n2s.find(index)==n2s.end()){
n2s[index]=id;
students[index].id=id;
}
students[index].gm=score;
}
for(int i=;i<n;i++){
cin>>id>>score;
if(score>) continue;
int index=string2num(id);
if(n2s.find(index)==n2s.end()){
n2s[index]=id;
students[index].id=id;
}
students[index].gf=score;
}
for(int i=;i<num;i++){
if(students[i].gp<) students[i].g=-;
else {
if(students[i].gm>students[i].gf){
float tt=0.4*students[i].gm+0.6*students[i].gf;
if((tt-(int)tt)>=0.5) students[i].g=(int)tt + ;
else students[i].g=(int)tt;
}
else students[i].g = students[i].gf;
}
if(students[i].g<) students[i].g=-;
}
sort(students,students+num,cmp);
for(int i=;i<num;i++){
if(students[i].g==-) break;
else {
printf("%s %d %d %d %d\n",students[i].id.c_str(),students[i].gp,students[i].gm,students[i].gf,students[i].g);
}
}
}
注意点:简单的排序题,但还是错了很多遍,第一次是maxn设太小了,题目是说每个不超过10000,所以三个加起来应该是不超过30000,导致最后一个测试点段错误。
第二个坑是算最后得分时要考虑小数的进位,不能直接取整
第三个坑题目里说了不超过900和100,以为没用,不会给错误分数,不加判断会出现超时,但提交第二次就没超时,也不知道为什么
ps:结构体和全局变量好多都是没用的其实,不过先加着也没事,最后出问题了再删吧
PAT A1137 Final Grading (25 分)——排序的更多相关文章
- PTA PAT排名汇总(25 分)
PAT排名汇总(25 分) 计算机程序设计能力考试(Programming Ability Test,简称PAT)旨在通过统一组织的在线考试及自动评测方法客观地评判考生的算法设计与程序设计实现能力,科 ...
- PAT 1137 Final Grading[一般][排序]
1137 Final Grading(25 分) For a student taking the online course "Data Structures" on China ...
- PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)
1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...
- PAT 甲级 1029 Median (25 分)(思维题,找两个队列的中位数,没想到)*
1029 Median (25 分) Given an increasing sequence S of N integers, the median is the number at the m ...
- PAT 甲级 1078 Hashing (25 分)(简单,平方二次探测)
1078 Hashing (25 分) The task of this problem is simple: insert a sequence of distinct positive int ...
- PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)
1032 Sharing (25 分) To store English words, one method is to use linked lists and store a word let ...
- PAT 1051 Pop Sequence (25 分)
返回 1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the ...
- PAT甲级——A1137 Final Grading【25】
For a student taking the online course "Data Structures" on China University MOOC (http:// ...
- A1137. Final Grading
For a student taking the online course "Data Structures" on China University MOOC (http:// ...
随机推荐
- Nodejs 和 Electron ubuntu下快速安装
查找时间管理软件的时候发现了superProductivity这个程序,使用electron进行开发,于是看了一下介绍,手痒了,尝试进行环境搭建,下一步慢慢补齐前端知识吧 nodejs安装 nodej ...
- EditPlus配置
1.设置语法和字符 2.调用浏览器 3.设置字符编码
- float清除浮动
清除浮动: 在非IE浏览器下,当容器的高度为auto,且容器的内容中有浮动(float为left或right)的元素,在这种情况下,容器的高度不能自动伸长以适应内容的高度,使得内容溢出到容器外面而影响 ...
- Java抽象类和接口的比较
一个软件设计的好坏,我想很大程度上取决于它的整体架构,而这个整体架构其实就是你对整个宏观商业业务的抽象框架,当代表业务逻辑的高层抽象层结构 合理时,你底层的具体实现需要考虑的就仅仅是一些算法和一些具体 ...
- loadrunner 运行脚本-Run-time Settings之Preferences设置
运行脚本-Run-time Settings之Preferences设置 by:授客 QQ:1033553122 打开Preferences设置对话框,这里提供了对运行时的参数选择设置 Enable ...
- Kotlin入门(6)条件分支的实现
上一篇文章介绍了字符串的相关操作,其中示例代码用到了if和for语句,表面上看,Kotlin对控制语句的处理与Java很像,可实际上,Kotlin在这方面做了不少的改进,所以本篇和下一篇文章就分别介绍 ...
- 高通 sensor 从native到HAL
app注册传感器监听 Android Sensor Framework 的整体架构如下图所示: 前几篇sensor相关的文章介绍了sensor的hal的知识,以press_sensor实时显示气压坐标 ...
- Fedroa 28 php 和 mail 命令,邮件发不出去
问题:在配置服务中,发现本地命令mail 和 php 邮件函数的邮件发送不出去. 解决方案: 安装 MTA 服务: postfix , sendmail 等. MTA 为 邮件传输代理 想要了解Lin ...
- Nginx Linux安装与部署
Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行. ...
- nginx服务器开启缓存、反向代理
一.反向代理配置 1.反向代理服务器配置如下 反向代理就是需要这一行proxy_pass来完成.当我们要访问后端web服务器的时候,我们只需要访问代理服务器就可以了,此时代理服务器就充当后端web服务 ...