首页 技术 正文
技术 2022年11月19日
0 收藏 778 点赞 2,820 浏览 3624 个字

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:结构体和全局变量好多都是没用的其实,不过先加着也没事,最后出问题了再删吧

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,076
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,400
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,812
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,894