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=(G​mid−term​​×40%+G​final​​×60%) if G​mid−term​​>G​final​​, or G​final​​ will be taken as the final grade G. Here G​mid−term​​ and G​final​​ 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 G​p​​'s; the second one contains M mid-term scores G​mid−term​​'s; and the last one contains N final exam scores G​final​​'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 G​p​​ G​mid−term​​ G​final​​ 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 分)——排序的更多相关文章

  1. PTA PAT排名汇总(25 分)

    PAT排名汇总(25 分) 计算机程序设计能力考试(Programming Ability Test,简称PAT)旨在通过统一组织的在线考试及自动评测方法客观地评判考生的算法设计与程序设计实现能力,科 ...

  2. PAT 1137 Final Grading[一般][排序]

    1137 Final Grading(25 分) For a student taking the online course "Data Structures" on China ...

  3. PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)

    1070 Mooncake (25 分)   Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...

  4. PAT 甲级 1029 Median (25 分)(思维题,找两个队列的中位数,没想到)*

    1029 Median (25 分)   Given an increasing sequence S of N integers, the median is the number at the m ...

  5. PAT 甲级 1078 Hashing (25 分)(简单,平方二次探测)

    1078 Hashing (25 分)   The task of this problem is simple: insert a sequence of distinct positive int ...

  6. PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)

    1032 Sharing (25 分)   To store English words, one method is to use linked lists and store a word let ...

  7. PAT 1051 Pop Sequence (25 分)

    返回 1051 Pop Sequence (25 分)   Given a stack which can keep M numbers at most. Push N numbers in the ...

  8. PAT甲级——A1137 Final Grading【25】

    For a student taking the online course "Data Structures" on China University MOOC (http:// ...

  9. A1137. Final Grading

    For a student taking the online course "Data Structures" on China University MOOC (http:// ...

随机推荐

  1. 转载 一位资深程序员大牛给予Java初学者的学习路线建议

    原文链接:http://geek.csdn.net/news/detail/242336 Java学习这一部分其实也算是今天的重点,这一部分用来回答很多群里的朋友所问过的问题,那就是你是如何学习Jav ...

  2. SpringCloud初体验之Eureka

    Eureka简介 SpringBoot简化了Spring工程的复杂度,之前复杂的Spring工程被拆分成了一个个小的SpringBoot工程.那么SpringBoot之间如何通讯,相互获取信息呢?这就 ...

  3. "美女相册"的 js 实现代码

    划重点拉!  先来解释一下子标题 这个所谓的美女相册呢  并不是和你们想的一样龌龊 当然了 好像看起来也很龌龊 但是很多的版面都能用到这个功能的 然后在此处  我要为我的my$函数来进行一个诠释 就是 ...

  4. 【读书笔记】iOS-设置应用的硬件需求

    如果你的应用需要一些特定的硬件设备才能运行,你可以在应用的Info.plist文件中添加应用运行所需的硬件列表.如果设备上没有这些硬件的话,你的应用将不会启动. 如图,找到Info.Plist---& ...

  5. 实践:配置keepalived实现主备热备份功能

    图: 配置文件: 主服务器的配置如下: global_defs { router_id NodeA}vrrp_instance VI_1 { state MASTER #设置为主服务器 interfa ...

  6. SVN SVN合并(Merge)与拉取分支(Branch/tag)操作简介

    SVN合并(Merge)与拉取分支(Branch/tag)操作简介 合并(Merge) 例子:把对feature_branch\project_name_v3.3.7_branch的修改合并到deve ...

  7. iOS-WKWebView的使用

    参考文章:http://www.cocoachina.com/ios/20180831/24753.html WK时苹果在iOS8.0之后推出的控件,相比于UIWebView: 内存消耗少: 解决了网 ...

  8. Fiddler抓包使用教程-QuickExec

    转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/73468287 本文出自[赵彦军的博客] 在 Fiddler 中自带了一个 Quic ...

  9. 泛化之美--C++11可变模版参数的妙用

    1概述 C++11的新特性--可变模版参数(variadic templates)是C++11新增的最强大的特性之一,它对参数进行了高度泛化,它能表示0到任意个数.任意类型的参数.相比C++98/03 ...

  10. eclipse下载教程

    Eclipse 是一个开放源代码的.基于 Java 的可扩展开发平台. Eclipse 是 Java 的集成开发环境(IDE),当然 Eclipse 也可以作为其他开发语言的集成开发环境,如C,C++ ...