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:// ...
随机推荐
- Java基础——Ajax(三)
Ajax 中文乱码问题(分两种情况) 1.对于Ajax 发的 post请求,服务端只需要 : request.setCharacterEncoding("utf-8"); 2.对 ...
- TestOps - 最健壮性的测试角色
一十一 发表于 2018-03-02 09:10:08 TestOps 最具影响力的测试运维一体化综合平台. DevOps实现了从代码到服务的快速落地,而TestOps集成了DevOps效率,更是 ...
- 理解微信小程序Wepy框架的三个事件交互$broadcast,$emit,$invoke
$broadcast: $broadcast事件是由父组件发起,所有子组件都会收到此广播事件,除非事件被手动取消.事件广播的顺序为广度优先搜索顺序,如上图,如果页面Page_Index发起一个$bro ...
- ComponetOne 2014 v3版本正式发布
2014年11月18日---ComponentOne Studio Enterprise 2014 v3版全球正式发布.ComponentOne Studio Enterprise是世界知名的Micr ...
- Linux 下修改网卡接口名
Linux下修改网卡接口名 by:授客 QQ:1033553122 (测试环境:CentOS-6.0-x86_64-bin-DVD1.iso+Vmware) 作用 可以用于解决类似如下Device n ...
- spring资源访问接口和资源加载接口
spring 资源访问接口 JDK提供的资源访问类,如java.net.URL.File等,不能很好地满足各种资源的访问需求,比如缺少从类路径或者Web容器的上下文中获取资源的操作类. 鉴于此,spr ...
- kNN处理iris数据集-使用交叉验证方法确定最优 k 值
基本流程: 1.计算测试实例到所有训练集实例的距离: 2.对所有的距离进行排序,找到k个最近的邻居: 3.对k个近邻对应的结果进行合并,再排序,返回出现次数最多的那个结果. 交叉验证: 对每一个k,使 ...
- 洗礼灵魂,修炼python(23)--自定义函数(4)—闭包进阶问题—>报错UnboundLocalError: local variable 'x' referenced before assignment
闭包(lexical closure) 什么是闭包前面已经说过了,但是由于遗留问题,所以单独作为一个章节详解讲解下 不多说,看例子: def funx(x): def funy(y): return ...
- HTML语言和CSS开发
第一张 HTML基础1.HTML:超文本标记语言(它除了文字,还能写图片.视频.音频.交互),他不是编程语言,它是标记语言2. <!DOCTYPE html> HTML5版本申明 < ...
- git merge 步骤
这两天用git比较多,自己学习的过程踩了不少误区,特意记录下来. 当多人合作开发使用git作为代码管理仓库时,要注意自己的更新不能冲掉别人的更新,因为自己一开始不了解的时候就出现了这种情况.首先一定要 ...