#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <algorithm> using namespace std; class Man {
public:
char id[];
int talent;
int virtue;
}; bool mycmp(const Man& a, const Man& b) {
int ta = a.virtue + a.talent;
int tb = b.virtue + b.talent;
if (ta > tb) {
return true;
} else if (ta < tb) {
return false;
}
// virtue + talent are equal, so compare virtue
if (a.virtue > b.virtue) {
return true;
} else if (a.virtue < b.virtue) {
return false;
}
// virtue is equal, so compare id
return strcmp(a.id, b.id) < ;
} void sort_print(vector<Man> &v) {
sort(v.begin(), v.end(), mycmp);
int len = v.size();
for (int i=; i<len; i++) {
printf("%s %d %d\n", v[i].id, v[i].virtue, v[i].talent);
}
} int main() {
int N, L, H;
scanf("%d%d%d", &N, &L, &H);
vector<Man> sage;
vector<Man> noble;
vector<Man> fool;
vector<Man> small; Man tmp;
int count = ;
for (int i=; i<N; i++) {
scanf("%s%d%d", tmp.id, &(tmp.virtue), &(tmp.talent));
if (tmp.virtue < L || tmp.talent < L) {
// discard
continue;
}
count++;
if (tmp.virtue >= H && tmp.talent >= H) {
sage.push_back(tmp);
} else if (tmp.virtue >= H) {
noble.push_back(tmp);
} else if (tmp.virtue >= tmp.talent) {
fool.push_back(tmp);
} else {
small.push_back(tmp);
}
} printf("%d\n", count); sort_print(sage);
sort_print(noble);
sort_print(fool);
sort_print(small); return ;
}

有时排序,差个ranking

PAT 1062 Talent and Virtue的更多相关文章

  1. PAT 1062 Talent and Virtue[难]

    1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...

  2. PAT-B 1015. 德才论(同PAT 1062. Talent and Virtue)

    1. 在排序的过程中,注意边界的处理(小于.小于等于) 2. 对于B-level,这题是比較麻烦一些了. 源代码: #include <cstdio> #include <vecto ...

  3. pat 1062. Talent and Virtue (25)

    难得的一次ac 题目意思直接,方法就是对virtue talent得分进行判断其归属类型,用0 1 2 3 4 表示 不合格 sage noblemen foolmen foolmen 再对序列进行排 ...

  4. 1062. Talent and Virtue (25)【排序】——PAT (Advanced Level) Practise

    题目信息 1062. Talent and Virtue (25) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B About 900 years ago, a Chine ...

  5. PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)

    1062 Talent and Virtue (25 分)   About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...

  6. 1062 Talent and Virtue (25 分)

    1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...

  7. 1062 Talent and Virtue (25)

    /* L (>=60), the lower bound of the qualified grades -- that is, only the ones whose grades of ta ...

  8. 1062.Talent and Virtue

    About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about ...

  9. 1062 Talent and Virtue (25分)(水)

    About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about ...

随机推荐

  1. Java面向对象之异常(异常处理方式)

    一.基础概念 (1)异常:Java程序在运行时期发生的不正常情况. Java就按照面向对象的思想对不正常情况进行描述和对象的封装. (2)异常问题分类: (Throwable:定义对于问题共性的功能. ...

  2. Java面向对象之内部类(访问格式)

    一.基础概念 1.内部类是定义在类中的类.A类需要直接访问B类中的成员时,可以将A类定义到B类中,作为B类的内部类存在. 2.内部类可以相当于外部类中的一个成员,可以被成员修饰符所修饰.(如:publ ...

  3. 「模拟赛20190327」 第二题 DP+决策单调性优化

    题目描述 小火车虽然很穷,但是他还是得送礼物给妹子,所以他前往了二次元寻找不需要钱的礼物. 小火车准备玩玩二次元的游戏,游戏当然是在一个二维网格中展开的,网格大小是\(n\times m\)的,某些格 ...

  4. jmeter 正则表达式的关联

    在工作中,用JM录制了登录---退出的脚本,但是多次请求后发现,总是返回的录制脚本的时候使用的账号的数据. 经过研究发现,login后,响应里的每次返回的token值是变化的,顺着往下看,下一个请求中 ...

  5. Qt 学习之路 2(46):视图和委托

    Home / Qt 学习之路 2 / Qt 学习之路 2(46):视图和委托 Qt 学习之路 2(46):视图和委托  豆子  2013年3月11日  Qt 学习之路 2  63条评论 前面我们介绍了 ...

  6. struts2学习笔记(四)——访问Servlet的API&结果跳转&数据封装

    一.Struts2访问Servlet的API 前面已经对Struts2的流程执行完成了,但是如果表单中有参数如何进行接收?又或者我们需要向页面保存一些数据,又要如何完成呢?我们可以通过学习Struts ...

  7. BZOJ 5168 && Luogu P3740 [HAOI2014]贴海报 线段树~~

    据说某谷数据十分水...但幸好BZOJ上也过了...话说我记得讲课时讲的是奇奇怪怪的离散化..但现在突然觉得什么都可以线段树瞎搞了...QAQ 直接就是这个区间有没有被覆盖,被覆盖直接return: ...

  8. XMAL基础

    XMAL基础(WPF编程宝典) XAML基础规则 XAML文档中的每个元素都映射为.Net类的一个实例.元素名称也完全对应于类名.例如:元素<Button>指示WPF创建Button对象 ...

  9. HihoCoder - 1142 三分法练手

    中文题面,原函数为三峰函数,先折半再三分 #include<bits/stdc++.h> using namespace std; const int maxn = 1e5+11; con ...

  10. 使用PHP并发执行任务–curl_multi应用

    使用PHP并发执行任务–curl_multi应用 原网址:http://lampblog.org/category/phpdev