PATA1137 测试点4

1.题意

给出一组学生成绩,将成绩合格的排序

2.代码

  1. 合格的成绩:Gp>=200 ,G>=60。注意不是Gfinal。
  2. 输入时只需要判断Gp是否合法,其他照常输入。
  3. map<name,int> 存储学生name
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
using namespace std;
const int maxn = 30010;
struct student {
  string name;
  int Gp = -1, GMid = -1, GFinal = -1, G;
} stu[maxn], ans[maxn];

map<string, int> name_to_int;

bool cmp(student a, student b) {
  if (a.G != b.G) return a.G > b.G;
  else return a.name < b.name;
}

int cnt = 0;
int get_id(string name) {
  if (name_to_int.find(name) == name_to_int.end()) {
    name_to_int[name] = cnt++;
  }
  return name_to_int[name];
}

//合法的值:线上存在且大于200,期末存在且大于60
int main() {
  //freopen("input.txt","r",stdin);
  int n, m, p;
  string name;
  int score;
  cin >> p >> m >> n;

  for (int i = 0; i < p; ++i) {
    cin.ignore();
    cin >> name >> score;
    if (score >= 200 && score <= 900) {   //线上大于200分才加入数组
      stu[get_id(name)].Gp = score;
      stu[get_id(name)].name = name;
    }
  }
  for (int i = 0; i < m; ++i) {
    cin.ignore();
    cin >> name >> score;
 
    stu[get_id(name)].GMid = score;
    stu[get_id(name)].name = name;

  }
  for (int i = 0; i < n; ++i) {
    cin.ignore();
    cin >> name >> score;

    stu[get_id(name)].GFinal = score;
    stu[get_id(name)].name = name;

  }
  //通过的输入完毕,处理G 期末不能不存在
  int cnt1 = 0;
  for (int i = 0; i < cnt; ++i) {
    if (stu[i].Gp != -1 && stu[i].GFinal != -1) {
      if (stu[i].GMid > stu[i].GFinal) { //期中大于期末
        stu[i].G = round(stu[i].GMid * 0.4 + stu[i].GFinal * 0.6);
        if (stu[i].G >= 60) ans[cnt1++] = stu[i];
      } else if (stu[i].GFinal >= 60) {
        stu[i].G = stu[i].GFinal;
        ans[cnt1++] = stu[i];
      }
    }
  }
  sort(ans, ans + cnt1, cmp);
  for (int i = 0; i < cnt1; ++i) {
    printf("%s %d %d %d %d\n", ans[i].name.c_str(), ans[i].Gp, ans[i].GMid, ans[i].GFinal, ans[i].G);
  }
  return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值