PAT 1062 Talent and Virtue

#include <cmath>
#include <vector>
#include <climits>
#include <iostream>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

class People {
public:
  int id;
  int virtue;
  int talent;
  int totalGrade;
  int flag = -1; // 4-sage;3-noble;2-fool;1-small;
};

bool compare1062(People p1, People p2) {
  if (p1.flag == p2.flag) {
    if (p1.totalGrade == p2.totalGrade) {
      if (p1.virtue == p2.virtue) {
        return p1.id < p2.id;
      }
      else {
        return p1.virtue > p2.virtue;
      }
    }
    else {
      return p1.totalGrade > p2.totalGrade;
    }
  }
  else {
    return p1.flag > p2.flag;
  }
}

int main() {

  int N, L, H;
  cin >> N >> L >> H;

  vector<People> checklist;
  while (N--) {
    People people;
    scanf("%d %d %d", &people.id, &people.virtue, &people.talent);
    people.totalGrade = people.virtue + people.talent;
    // those with both grades not below this line are considered as the "sages", and will be ranked in non-increasing order according to their total grades
    if (people.virtue >= H && people.talent >= H) {
      people.flag = 4; // sage
    }
    // Those with talent grades below H but virtue grades not are cosidered as the "noblemen", and are also ranked in non-increasing order according to their total grades, but they are listed after the "sages"
    else if (people.virtue >= H && people.talent < H && people.talent >= L) {
      people.flag = 3; // noble
    }
    // Those with both grades below H, but with virtue not lower than talent are considered as the "fool men"
    else if (people.virtue < H && people.virtue >= L && people.talent < H && people.talent >= L && people.virtue >= people.talent) {
      people.flag = 2; // fool
    }
    else if (people.virtue >= L && people.talent >= L) {
      // The rest of people whose grades both pass the L line are ranked after the "fool men".
      people.flag = 1; // small
    }
    else {
    // only the ones whose grades of talent and virtue are both not below this line will be ranked
    }

    if (people.flag > 0) checklist.push_back(people);
  }

  sort(checklist.begin(), checklist.end(), compare1062);

  cout << checklist.size() << endl;
  for (int i = 0; i < checklist.size(); i++) {
    printf("%d %d %d\n", checklist[i].id, checklist[i].virtue, checklist[i].talent);
  }

  return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值