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. X问题(中国剩余定理+不互质版应用)hdu1573

    X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  2. LintCode Binary Search

    For a given sorted array (ascending order) and a target number, find the first index of this number ...

  3. 【读书笔记】iOS-更改布局行为

    View---->Assistant Editor---->查看可用的布局. 参考资料:<Xcode实战开发>  

  4. 【读书笔记】iOS-强类型与弱类型

    id类型是一个通用类型,OC使用id表示任意类型的对象,它可以作为一个占位符表示这是一个不确定的类型的对象或者引用.因此,所有的对象都 可以用id来表示.这很有用,想象一下,如果你需要实现一个通用的链 ...

  5. Ansible--inventory

    简介 Inventory 是 Ansible 管理主机信息的配置文件,相当于系统 HOSTS 文件的功能,默认存放在 /etc/ansible/hosts.为方便批量管理主机,便捷使用其中的主机分组, ...

  6. NoHttp封装--02 自定义请求

    bean实体类请求: 1.bean import java.io.Serializable; import com.alibaba.fastjson.annotation.JSONField; pub ...

  7. 工作中常用到的Vim命令

    最近工作中需要到linux服务器上更改文件,苦于对vim的各种命令不熟悉,今天特此总结并熟悉一下各种vim命令,好提高工作效率.后期持续更新 vim编辑器个人设置 先复制一份vim配置模板到个人目录下 ...

  8. enum类使用

    状态常量类使用enum public class TestEnums{ public enum STATUS{ NOMAL("01","正常"), DELETE ...

  9. HTML5文件API之FileReader

    在文件上传之前,我们总想预览一下文件内容,或图片样子,html5 中FileReader正好提供了2种方法,可以在不上传文件的情况下,预览文件内容. 图片预览:readAsDataURL(file); ...

  10. 《R数据挖掘入门》彩色插图(第9章)

    图9.5  图9.9