#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. UX | 最小可行性技能

    简评:本文介绍了最小 UX 需要技能(可以看成设计版 MVP),包括用不同视角看事情,从回馈中学习等等 ~ 呐,可能刚入门设计的时候,会让一堆工具弄得眼花缭乱.其实呢,并不一定要每样都会使用,举一反三 ...

  2. GitHub 十大 CI 工具

    简评:GitHub 上最受欢迎的 CI 工具. 持续集成(Continuous integration)指的是,频繁地(一天多次)将代码集成到主干. 持续集成工具让产品可以快速迭代,同时还能保持高质量 ...

  3. 连接池、数据源、JNDI三者间的关系及用法

    连接池:连接池是由容器(比如Tomcat)提供的,用来管理池中的连接对象.连接池自动分配连接对象并对闲置的连接进行回收.连接池中的连接对象是由数据源(DataSource)创建的.连接池(Connec ...

  4. I/O(输入/输出)---序列化与反序列化

    概念: 序列化就是将对象的状态存储到特定的介质中的过程,也就是将对象状态转换为可保持或传输格式的过程. 反序列化则是从特定存储介质中将数据重新构建对象的过程.可以将存储在文件上的对象信息读取,然后重新 ...

  5. 深度学习TensorFlow常用函数

    tensorflow常用函数 TensorFlow 将图形定义转换成分布式执行的操作, 以充分利用可用的计算资源(如 CPU 或 GPU.一般你不需要显式指定使用 CPU 还是 GPU, Tensor ...

  6. CSS复合选择器

    复合选择器是由两个或多个基础选择器,通过不同的方式组合而成的,目的是为了可以选择更准确更精细的目标元素标签. 交集选择器 交集选择器由两个选择器构成,其中第一个为标签选择器,第二个为class选择器, ...

  7. Android 对话框的应用1

    1.介绍 2.作用 (1)消息提示对话框 (2)简单列表对话框 (3)单选列表对话框 (4)多选对话框 (5)自定义对话框 3.java后台代码 package com.lucky.test28dia ...

  8. css flex 使内容 水平居中 的方法...

    刚开始以为是  justify-content : center 设置为 居中... 的确,,当 元素满了时 的确能 居中.但是 当只有一个元素时,这一个元素也会居中... 想了半天没找到方法..突然 ...

  9. centos上安装theano和Lasagne

    1.安装theano所需的包 sudo yum install python-devel python-nose python-setuptools gcc gcc-gfortran gcc-c++ ...

  10. Tensorlflow-神经网络解决非线性回归问题

    import tensorflow as tfimport numpy as npimport matplotlib.pyplot as plt #使用numpy生成200个随机点,范围从-0.5到0 ...