#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. loj #2509. 「AHOI / HNOI2018」排列

    #2509. 「AHOI / HNOI2018」排列   题目描述 给定 nnn 个整数 a1,a2,…,an(0≤ai≤n),以及 nnn 个整数 w1,w2,…,wn.称 a1,a2,…,an 的 ...

  2. eazyui 或bootstrap table表格里插入图片,点击查看大图

    columns: [ {field: 'state',checkbox: true,align: 'center',valign: 'middle'}, {field: 'contacts',sort ...

  3. XAF对Attribute的总结

    [Aggregated] 没有参数,作用于a property or a field,并且只能是持久类的引用或者XPCollection.实现两个持久类的级联删除的功能. [Association(& ...

  4. 小程序tabBar显示问题

    我一直在纠结为什么小程序在有的页面显示,有的页面不显示 查了一下才知道,小程序tabBar只在tabBar中的list定义了页面的才会显示,其余页面不会显示 如下例:tabBar只在画红框的页面显示

  5. springcloud微服务总结二 注册中心

    一:netflix和springcloud关系 netflix公司开源了很多组件,包括服务注册与发现(Netflix Eureka).断路器(Netflix Hystrix).负载均衡(Netflix ...

  6. Python闭包需要注意的问题

    定义   python中的闭包从表现形式上定义为:如果在一个内部函数里,对在外部作用域(但不是在全局作用域)的变量进行引用,那么内部函数就被认为是闭包(closure),也就是说内层函数引用了外层函数 ...

  7. IntelliJ IDEA(Android Studio)设置代码的快捷编辑模板Live Templates

    1.file---->setttings 2.editor--->live template 3.点击右侧的+ 4.设置模板 注意:Abbreviation为代码模板的缩写.

  8. 【贪心】洛谷P1607 [USACO09FEB]庙会班车Fair Shuttle 题解

        不是很容易写出正解的贪心问题. 题目描述 Although Farmer John has no problems walking around the fair to collect pri ...

  9. AtCoder Beginner Contest 113 B

    B - Palace Time limit : 2sec / Memory limit : 1024MB Score: 200 points Problem Statement A country d ...

  10. vi下搜索文本

    ) /user ) n 下一个匹配 ) N 上一个匹配 ) ?user 从结尾开始搜索 ) :nohlsearch 关闭高亮显示6) :100 跳转到第100行