#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. arx创建作用域(于)当前文档全局变量

    普通的全局变量是作用于整个AutoCAD程序中,所有的文档都将能存取,某些时候,我们需要某一个全局变量仅仅在当前文档有效,便于程序之间通信或者变量值记忆. 在高版本的objectARX向导中,已经为我 ...

  2. spring+hibernate中的事务

    上下文: 从数据库服务器上获取数据可以,保存的时候增加了事务提交,即em.flush方法,报错no transaction in progress 报错信息: no transaction in pr ...

  3. birth

    第一次开通博客, 今天开始了计算机方面的学习,我将通过博客来总结自己的学习内容以及分享学习经验,同时我将分享在技术方面的所见所闻以及所思所想,希望能和大家一起探讨,共同进步~

  4. Python爬取招聘信息,并且存储到MySQL数据库中

    前面一篇文章主要讲述,如何通过Python爬取招聘信息,且爬取的日期为前一天的,同时将爬取的内容保存到数据库中:这篇文章主要讲述如何将python文件压缩成exe可执行文件,供后面的操作. 这系列文章 ...

  5. php 缓冲函数

    php.ini中有两个关键参数会影响到php的缓存输出控制: output_buffering :on/off 或者整数 .设置为 on 时,将在所有脚本中使用输出缓存控制,不限制缓存的大小.而设置为 ...

  6. python学习,day1:循环判断基本语句的几个代码

    # coding=utf-8 # Author: RyAn Bi count = 0 '''while True : print('count:',count) count = count + 1 i ...

  7. P3704 [SDOI2017]数字表格 (莫比乌斯反演)

    [题目链接] https://www.luogu.org/problemnew/show/P3704 [题解] https://www.luogu.org/blog/cjyyb/solution-p3 ...

  8. LeetCode4. 两个排序数组的中位数

    4. 两个排序数组的中位数 问题描述 There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the ...

  9. Joi图标

    刚开始浏览API的时候,旁边这个图片还真没明白是啥意思.现在才明白过来:),检测工具嘛,哈哈.

  10. PIE SDK图像裁剪

    1.算法功能简介 图像裁剪的目的是获取选定的影像范围区域.图像裁切工具提供像素范围裁切.矢量裁切.栅格图像裁切和几何图元裁切四种方式. 像素范围裁切是基于像素坐标获取矩形裁切区域的裁切方式:矢量裁切是 ...