PAT 1062 Talent and Virtue
#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的更多相关文章
- PAT 1062 Talent and Virtue[难]
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...
- PAT-B 1015. 德才论(同PAT 1062. Talent and Virtue)
1. 在排序的过程中,注意边界的处理(小于.小于等于) 2. 对于B-level,这题是比較麻烦一些了. 源代码: #include <cstdio> #include <vecto ...
- pat 1062. Talent and Virtue (25)
难得的一次ac 题目意思直接,方法就是对virtue talent得分进行判断其归属类型,用0 1 2 3 4 表示 不合格 sage noblemen foolmen foolmen 再对序列进行排 ...
- 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 ...
- PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...
- 1062 Talent and Virtue (25 分)
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...
- 1062 Talent and Virtue (25)
/* L (>=60), the lower bound of the qualified grades -- that is, only the ones whose grades of ta ...
- 1062.Talent and Virtue
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about ...
- 1062 Talent and Virtue (25分)(水)
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about ...
随机推荐
- 修改两行代码,让nginx支持phpinfo模式
Nginx服务器默认不支持pathinfo, 在需要pathinfo支持的程序中(如thinkphp),则无法支持”/index.php/Home/Index/index”这种网址. 网上流传的解决办 ...
- PHP简单实现一言 / 随机一句功能
很多网站都喜欢在页面中加个一言,不过一般都是调用的第三方api.其实,使用万能的php能用短短的几行代码就实现该功能! 将下列代码复制并粘贴到 api.php 中保存,你的专属“一言” API 就搭建 ...
- js 对象 浅拷贝 和 深拷贝
网上发现一个比较好的博客 阮一峰的感觉很不错推荐大家看看. http://www.ruanyifeng.com/blog/it/javascript/ 接下来看一下这两个拷贝方法 1.浅拷贝 拷贝就是 ...
- 【转】IDEA快捷键功能说明及Eclipse对应操作
1.Ctrl+z是撤销快捷键 2.如果想恢复Ctrl+z 掉的内容,按快捷键为:Ctrl + Shift + Z.方可 3.Ctrl-H(Browse Type Hierarchy) Ctrl + A ...
- 制作一句话图片马(NO)
- python 的内置模块 re
在 pattern 的 “” 前面需要加上一个 r 用来表示这是正则表达式, 而不是普通字符串 >>> import re >>> ptn = r"r[a ...
- HDU 5938 Kingdom of Obsession(数论 + 二分图匹配)
题意: 给定S,N,把S+1,S+2,...S+N这N个数填到1,2,...,N里,要求X只能填到X的因子的位置.(即X%Y=0,那么X才能放在Y位置) 问是否能够放满. 分析:经过小队的分析得出的结 ...
- HDU - 2089 数位DP 初步
中文题目,不要62和4 从高位往低位DP,注意有界标志limit的传递 dp2记忆有界情况下的计数结果,据说用处不大 我所参考的入门文章就是半搜索(有界)半记忆(无界)的 进阶指南中提出dfs维度有多 ...
- PhpExcel中文帮助手册|PhpExcel使用方法 ( 后面有部分没有显示出来 可以编辑中看到!!)
下面是总结的几个使用方法 include 'PHPExcel.php'; include 'PHPExcel/Writer/Excel2007.php'; //或者include 'PHPExcel/ ...
- [转] PuTTY + Xming 远程使用 Linux GUI
[From] http://www.zw1840.com/blog/zw1840/2008/10/putty-xming-linux-gui.html By zw1840 on October 28, ...