1137 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=(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

题目大意:看完题感觉还是比较简单的,学生们都有一个id,不超过20个英文字母和数字,并且有上机成绩、期中成绩、期末成绩、最终成绩。最终成绩的判断是由期中成绩*40%+期末成绩*60%,如果期中成绩<期末成绩,那直接由期末成绩构成。那么谁能够获得证书呢?编程成绩>=200&&最终成绩>=60。

//首先我想用map,但是map可以映射一个结构体吗?关键是这个id怎么映射啊?!

//用map映射啊,你忘了那道图论的 如何到ROM的题目了吗?就是把每个城市的名字映射成id,还有一个map是将id映射为名字。

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include<math.h>
using namespace std;
map<string,int> mp;
struct Stu{
string id;
int gp,gmid,gfin,g;
Stu(){gp=-;gmid=-;gfin=-;
}
}stu[];
bool cmp(Stu& a,Stu& b){
return a.g!=b.g?a.g>b.g:a.id<b.id;
}
int main() {
int m,n,k;
cin>>m>>n>>k;
int cnt=,temp;//共有多少个人。
string s;
for(int i=;i<m;i++){ cin>>s>>temp;
if(mp[s]==){
mp[s]=cnt++;
stu[mp[s]].id=s;
}
stu[mp[s]].gp=temp;
}
for(int i=;i<n;i++){
cin>>s>>temp;
if(mp[s]==){
mp[s]=cnt++;
stu[mp[s]].id=s;
}
stu[mp[s]].gmid=temp;
}
for(int i=;i<k;i++){
cin>>s>>temp;
if(mp[s]==){
mp[s]=cnt++;
stu[mp[s]].id=s;
}
stu[mp[s]].gfin=temp;
if(stu[mp[s]].gmid<=stu[mp[s]].gfin){
stu[mp[s]].g=stu[mp[s]].gfin;
}else {
stu[mp[s]].g=round(stu[mp[s]].gmid*0.4+stu[mp[s]].gfin*0.6);
//怎么才能在这四舍五入呢?!
}
}
sort(stu,stu+cnt,cmp);
for(int i=;i<cnt;i++){
if(stu[i].gp>=&&stu[i].g>=)
cout<<stu[i].id<<" "<<stu[i].gp<<" "<<stu[i].gmid<<" "<<stu[i].gfin<<" "<<stu[i].g<<'\n';
} return ;
}

//写成了这样,第一次提交编译错误,发现是round函数,在CB中是好使的,但是提交到pat平台上时需要加上math.h头文件!

//第二次提交,发生了答案错误和段错误,后两个测试点没过。

//我知道为什么发生段错误了,因为虽然m,n,k每一个数都是在10000之内,但是并不能保证总人数就是10000之内啊!

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include<math.h>
using namespace std;
map<string,int> mp;
struct Stu
{
string id;
int gp,gmid,gfin,g;
Stu()
{
gp=-;
gmid=-;
gfin=-;
}
} stu[];
bool cmp(Stu& a,Stu& b)
{
return a.g!=b.g?a.g>b.g:a.id<b.id;
}
int main()
{
int m,n,k;
cin>>m>>n>>k;
int cnt=,temp;//共有多少个人。
string s;
for(int i=; i<m; i++) //如果机试不够或者是没有机试分数,那必然不能获得证书。
{
cin>>s>>temp;
if(temp>=)
{
mp[s]=cnt++;
stu[mp[s]].id=s;
stu[mp[s]].gp=temp;
}
else
{
mp[s]=-;
}
}
for(int i=; i<n; i++)
{
cin>>s>>temp;
if(mp[s]!=-) //而且机试成绩是满足条件的!
{
if(mp[s]==)
{
mp[s]=cnt++;
stu[mp[s]].id=s;
}
stu[mp[s]].gmid=temp;
}
}
for(int i=; i<k; i++)
{
cin>>s>>temp;
if(mp[s]!=-)
{
if(mp[s]==)
{
mp[s]=cnt++;
stu[mp[s]].id=s;
}
stu[mp[s]].gfin=temp;
if(stu[mp[s]].gmid<=stu[mp[s]].gfin)
{
stu[mp[s]].g=stu[mp[s]].gfin;
}
else
{
stu[mp[s]].g=round(stu[mp[s]].gmid*0.4+stu[mp[s]].gfin*0.6);
//怎么才能在这四舍五入呢?!
}
}
}
sort(stu,stu+cnt,cmp);
for(int i=; i<cnt; i++)
{
if(stu[i].gp>=&&stu[i].g>=)
cout<<stu[i].id<<" "<<stu[i].gp<<" "<<stu[i].gmid<<" "<<stu[i].gfin<<" "<<stu[i].g<<'\n';
} return ;
}

//后来我这样去写,测试点2过不去,后来才发现,有可能是一个人的机试成绩,并没有在输入机试时存在,那么此时她就是-1!!。需要再改判断条件!

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include<math.h>
using namespace std;
map<string,int> mp;
struct Stu
{
string id;
int gp,gmid,gfin,g;
Stu()
{
gp=-;
gmid=-;
gfin=;
g=;//我的妈呀,我这里居然没有初始化g,难道是这里的错?
}
} stu[];
bool cmp(Stu& a,Stu& b)
{
return a.g!=b.g?a.g>b.g:a.id<b.id;
}
int main()
{
int m,n,k;
cin>>m>>n>>k;
int cnt=,temp;//共有多少个人。
string s;
for(int i=; i<m; i++) //如果机试不够或者是没有机试分数,那必然不能获得证书。
{
cin>>s>>temp;
if(temp>=)
{
mp[s]=cnt++;
stu[mp[s]].id=s;
stu[mp[s]].gp=temp;
}
}
for(int i=; i<n; i++)
{
cin>>s>>temp;
if(mp[s]!=)//其实只要统计机试中出现过的人就好!
{
stu[mp[s]].gmid=temp;
}
}
for(int i=; i<k; i++)
{
cin>>s>>temp;
if(mp[s]!=)//如果没有期末成绩的,那么一定不能输出,这就找到我的问题了,
//我下面排序和输出都是用的cnt!!!.那么还需要再计一次!
{
stu[mp[s]].gfin=temp;
if(stu[mp[s]].gmid<=stu[mp[s]].gfin)
{
stu[mp[s]].g=stu[mp[s]].gfin;
}
else
{
stu[mp[s]].g=int(stu[mp[s]].gmid*0.4+stu[mp[s]].gfin*0.6+0.5);
//怎么才能在这四舍五入呢?!
}
}
}
//if(cnt!=ct)cnt=ct;不能这样,因为那些原来的不符合的仍然在stu里顺序存在呢。。。
//看来只能在for循环一遍了,将答案存储再去排序和输出。
vector<Stu> ans;
for(int i=;i<cnt;i++){
if(stu[i].g>=)ans.push_back(stu[i]);
}
sort(ans.begin(),ans.end(),cmp);
for(int i=; i<ans.size(); i++)
{
cout<<ans[i].id<<" "<<ans[i].gp<<" "<<ans[i].gmid<<" "<<ans[i].gfin<<" "<<ans[i].g<<'\n';
} return ;
}

//终于AC了,终于想出来原因了。智障吧,你用mp[s]==0去判断这个s是否存在,你还居然一开始把cnt初始化为0,让第一个人映射到0!!!!你这不是智障是啥。

PAT 1137 Final Grading[一般][排序]的更多相关文章

  1. PAT 1137 Final Grading

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

  2. PAT A1137 Final Grading (25 分)——排序

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

  3. PAT 甲级 1137 Final Grading

    https://pintia.cn/problem-sets/994805342720868352/problems/994805345401028608 For a student taking t ...

  4. 1137 Final Grading

    题意:排序题. 思路:通过unordered_map来存储考生姓名与其成绩信息结构体的映射,成绩初始化为-1,在读入数据时更新各个成绩,最后计算最终成绩并把符合条件的学生存入vector,再排序即可. ...

  5. 1137 Final Grading (25 分)

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

  6. PAT_A1137#Final Grading

    Source: PAT A1137 Final Grading (25 分) Description: For a student taking the online course "Dat ...

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

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

  8. A1137. Final Grading

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

  9. PAT 1012 The Best Rank 排序

    To evaluate the performance of our first year CS majored students, we consider their grades of three ...

随机推荐

  1. js表单计算金额问题

    <table width="600" border="1" align="center" style="text-align ...

  2. DoBox 下载

    DoBox下载 一款简单十分好用的办公助手,用于记录您接下来需要做的事情.待办事项小工具 - DoBox DoBox下载 下载地址:http://www.wxzzz.com/?id=141 最新版本: ...

  3. mybatis由浅入深day01_5.3 Mapper动态代理方法

    5.3 Mapper动态代理方法(程序员只需要写mapper接口(相当于dao接口)) 5.3.1 实现原理(mapper代理开发规范) 程序员还需要编写mapper.xml映射文件 程序员编写map ...

  4. Java精选笔记_IO流(字节流、InputStream、OutputStream、字节文件、缓冲区输入输出流)

    字节流 操作图片数据就要用到字节流. 字符流使用的是字符数组char[],字节流使用的是字节数组byte[]. 字节流读写文件 针对文件的读写,JDK专门提供了两个类,分别是FileInputStre ...

  5. JavaScript jQuery 笔记

    资料来源:http://www.w3school.com.cn/jquery/index.asp http://files.cnblogs.com/files/defineconst/jQuery.r ...

  6. NodeJS-004-Oracle驱动编译

    一.参考文章 https://community.oracle.com/docs/DOC-931127 http://www.cnblogs.com/stone_w/p/4794747.html ht ...

  7. Python 高斯坐标转经纬度算法

    # 高斯坐标转经纬度算法# B=大地坐标X# C=大地坐标Y# IsSix=6度带或3度带def GetLatLon2(B, C,IsSix): #带号 D = math.trunc(C / 1000 ...

  8. ch6-定制数据对象(打包代码和数据)

    为了看出数据属于哪个选手,教练向各个选手的数据文件中添加了标识数据:选手全名,出生日期,计时数据. 例如:sarah文件的数据更新为: Sarah Sweeney,2002-6-17,2:58,2.5 ...

  9. linux--GCC用法

    1简介 2简单编译 2.1预处理 2.2编译为汇编代码(Compilation) 2.3汇编(Assembly) 2.4连接(Linking) 3多个程序文件的编译 4检错 5库文件连接 5.1编译成 ...

  10. Apache nutch1.5 & Apache solr3.6

    第1章引言 1.1nutch和solr Nutch 是一个开源的.Java 实现的搜索引擎.它提供了我们运行自己的搜索引擎所需的全部工具. Solr 拥有像 web-services API 的独立的 ...