PAT A1137 Final Grading

PAT A1137 Final Grading

在这里插入图片描述

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
wordmeaning
grading sheets评分表
no less than 60 out of 100100个中不少于60个
  • 分析:
    一个人获得证书的条件是:首先得有programming assignments成绩,所以输入ass成绩后,在输入mid和fin只要输入有ass成绩的人即可(不需要考虑连ass成绩都没有的人)
    开始想复杂了:用一个idex记录总人数,输入完ass以后,再输入mid/fin时遇到没有ass成绩的人也添加进去idex++了,这会导致错误(没有ass成绩但其他合格)

  • 思路 1:

  1. 建一个结构体存储考生信息,再建一个
  2. map记录有ass成绩的考生,姓名与id号的映射
  3. 再输入mid/fin时,只需要输入map里有的考生即可!
  4. 排序输出
  • code 1:
#include <iostream>
#include <unordered_map>
#include <algorithm>
using namespace std;
const int maxn = 10010;
int ass, mid, fin;
struct Stu{
	string id;
	int scp, scm, scf,  g;
	Stu(){scm = g = -1;}
}stu[maxn]; 
unordered_map<string, int> ntoi;
//unordered_map<int, string> iton;
bool cmp(Stu a, Stu b){
	return a.g != b.g ? a.g > b.g : a.id < b.id;
}
int main(){
	string name;
	int sp, sm, sf, tid;
	scanf("%d %d %d", &ass, &mid, &fin);
	for(int i = 0; i < ass; ++i){
		cin >> name >> sp;
		stu[i].id = name;
		stu[i].scp = sp;
		ntoi[name] = i;
	}
	for(int i = 0; i < mid; ++i){
		cin >> name >> sm;
		if(ntoi.find(name) != ntoi.end()) stu[ntoi[name]].scm = sm;
	}
	for(int i = 0; i < fin; ++i){
		cin >> name >> sf;
		if(ntoi.find(name) != ntoi.end()) stu[ntoi[name]].scf = sf;
	}	
	for(int i = 0; i < ass; ++i){
		int mg = stu[i].scm, fg = stu[i].scf;
		int fing = mg > fg ? int(mg * 0.4 + fg * 0.6 + 0.5) : fg;
		if(stu[i].scp >= 200 && fing >= 60)	stu[i].g = fing;
	}
	sort(stu, stu+ass, cmp);
	for(int i  = 0; i < ass; ++i){
		if(stu[i].g > 0)
			cout << stu[i].id <<" "<< stu[i].scp<<" "<< stu[i].scm <<" "<< stu[i].scf<<" "<< stu[i].g <<endl; 
		else break;
	}	
	return 0;
} 
  • T2 code:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10010;
unordered_map<string, int> mp;
struct Stu{
	string id;
	int G[5];
	Stu(){
		memset(G, -1, sizeof(G));
	}
}stu[maxn];
bool cmp(Stu a, Stu b){
	return a.G[3] != b.G[3] ? a.G[3] > b.G[3] : a.id < b.id;
}
int main(){
	int p, m, n, score, idex = 0;
	string name;
	scanf("%d %d %d", &p, &m, &n);
	for(int i = 0; i < p; ++i){
		cin >> name >> score;
		if(score >= 200){
			stu[idex].id = name; 
			stu[idex].G[0] = score;
			mp[name] = idex++;
		}
	}
	for(int i = 0; i < m; ++i){
		cin >> name >> score;
		if(mp.find(name) != mp.end()){
			int tid = mp[name];
			stu[tid].G[1] = score;
		}
	}
	for(int i = 0; i < n; ++i){
		cin >> name >> score;
		if(mp.find(name) != mp.end()){
			int tid = mp[name];
			stu[tid].G[2] = score;
		}
	}
	for(int i = 0; i < idex; ++i){
		int ms = stu[i].G[1], fs = stu[i].G[2];
		if(ms > fs) stu[i].G[3] = round(0.4 * ms + 0.6 * fs);	//Wrong 1:!四舍五入!!! 
		else stu[i].G[3] = fs;
	}
	sort(stu, stu + idex, cmp);
	for(int i = 0; i < idex; ++i){
		if(stu[i].G[3] >= 60){
			Stu tmp = stu[i];
			printf("%s %d %d %d %d\n", tmp.id.c_str(), tmp.G[0], tmp.G[1], tmp.G[2], tmp.G[3]);
		}
	}
	return 0;
} 
  • T4 code:
#include <bits/stdc++.h>
using namespace std;

struct stu
{
    string id;
    int score[4];
    stu() { memset(score, -1, sizeof(score)); }
};
unordered_map<string, stu> mp;
vector<stu> ans;
bool cmp(stu & a, stu & b)
{
    if(a.score[3] != b.score[3])
    {
        return a.score[3] > b.score[3];
    }else
    {
        return a.id < b.id;
    }
}
int main()
{
    int np, nm, nf;
    scanf("%d %d %d", &np, &nm, &nf);
    for(int i = 0; i < np; ++i)
    {
        string id; int tscore;
        cin >> id >> tscore;
        if(tscore < 200) continue;
        mp[id].id = id;
        mp[id].score[0] = tscore;
    }
    for(int i = 0; i < nm; ++i)
    {
        string id; int tscore;
        cin >> id >> tscore;
        if(mp.find(id) == mp.end()) continue;
        mp[id].score[1] = tscore;
    }
    for(int i = 0; i < nf; ++i)
    {
        string id; int tscore;
        cin >> id >> tscore;
        if(mp.find(id) == mp.end()) continue;
        mp[id].score[2] = tscore;
    }
    for(auto it = mp.begin(); it != mp.end(); ++it)
    {
        int gf;
        if(it->second.score[1] > it->second.score[2])
        {
            gf = round(0.4 * it->second.score[1] + 0.6 * it->second.score[2]);
        }else
        {
            gf = it->second.score[2];
        }
        if(gf < 60) continue;
        stu tmp;
        tmp.id = it->first;
        for(int i = 0; i < 3; ++i)
            tmp.score[i] = it->second.score[i];
        tmp.score[3] = gf;
        ans.push_back(tmp);
    }
    sort(ans.begin(), ans.end(), cmp);
    for(int i = 0; i < ans.size(); ++i)
    {
        cout << ans[i].id;
        for(int j = 0; j < 4; ++j)
            printf(" %d", ans[i].score[j]);
        printf("\n");
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值