1. 在排序的过程中,注意边界的处理(小于、小于等于)

2. 对于B-level,这题是比較麻烦一些了。

源代码:

#include <cstdio>
#include <vector>
#include <algorithm> using namespace std; struct People
{
int m_id;
int m_virtue;
int m_talent;
People(int id, int virtue, int talent): m_id(id), m_virtue(virtue), m_talent(talent) {}
void print()
{
printf("%08d %d %d\n", m_id, m_virtue, m_talent);
}
friend bool operator< (const People& a, const People& b)
{
if (a.m_virtue+a.m_talent != b.m_virtue+b.m_talent)
{
return a.m_virtue+a.m_talent > b.m_virtue+b.m_talent;
} else if (a.m_virtue != b.m_virtue)
{
return a.m_virtue > b.m_virtue;
} else
{
return a.m_id < b.m_id;
}
}
}; vector<People> sage, noble_man, fool_man, small_man;
int n, l, h;
int id, virtue, talent; int main()
{
scanf("%d%d%d", &n, &l, &h);
for (int i = 0; i < n; ++ i)
{
scanf("%d%d%d", &id, &virtue, &talent);
if (virtue < l || talent < l)
{
continue;
} else if (virtue >= h && talent >= h)
{
sage.push_back( People(id, virtue, talent) );
} else if (virtue >= h)
{
noble_man.push_back( People(id, virtue, talent) );
} else if (virtue >= talent)
{
fool_man.push_back( People(id, virtue, talent) );
} else
{
small_man.push_back( People(id, virtue, talent) );
}
} sort(sage.begin(), sage.end());
sort(noble_man.begin(), noble_man.end());
sort(fool_man.begin(), fool_man.end());
sort(small_man.begin(), small_man.end()); printf("%d\n", sage.size() + noble_man.size() + fool_man.size() + small_man.size());
for (size_t i = 0; i < sage.size(); ++ i)
{
sage[i].print();
}
for (size_t i = 0; i < noble_man.size(); ++ i)
{
noble_man[i].print();
}
for (size_t i = 0; i < fool_man.size(); ++ i)
{
fool_man[i].print();
}
for (size_t i = 0; i < small_man.size(); ++ i)
{
small_man[i].print();
} return 0;
}

PAT-B 1015. 德才论(同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. 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 ...

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

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

  4. 1062 Talent and Virtue (25 分)

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

  5. PAT乙级 1015. 德才论 (25)

    1015. 德才论 (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Li 宋代史学家司马光在<资治通鉴&g ...

  6. 【PAT】1015 德才论 (25)(25 分)

    1015 德才论 (25)(25 分) 宋代史学家司马光在<资治通鉴>中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得 ...

  7. pat 乙级 1015. 德才论 (25) c++

     http://39.106.25.239 个人网站 欢迎访问 交流 1015. 德才论 (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Sta ...

  8. PAT Basic 1015 德才论 (25 分)

    宋代史学家司马光在<资治通鉴>中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人 ...

  9. pat 1062. Talent and Virtue (25)

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

随机推荐

  1. 高焕堂《android从程序员到架构师之路》 YY讲坛直面大师学习架构设计

    <android从程序员到架构师之路>YY讲坛活动:  sundy携手高焕堂老师全程YY答疑 与大师一起,分享android技术 时间:7月21日下午2:00   报名联系QQ:22243 ...

  2. 调用ShellExecute所须要头文件

    调用ShellExecute所须要头文件 #include   "windows.h " #include   "shellapi.h "

  3. semaphore实现浏览器的读写原理

    在编程范式中的斯坦福大学的老师说了一个例子:好比世界上就只有一台互联网的服务器,当我们浏览网页的时候,就好比服务器进行了写操作,而浏览器则进行了读操作. 我如果用简单的伪代码c++写出来是这个样子的: ...

  4. PHP中遍历stdclass object 及 json 总结[中国航天神舟十号以json形式向地面返回数据]

    $test=Array ( [0] => stdClass Object ( [tags] => 最快的车,Bloodhound,SSC [id] => 48326888 11 从网 ...

  5. Struts 2中的constant详解

    通过对这些属性的配置,可以改变Struts 2 框架的一些默认行为,这些配置可以在struts.xml文件中完成,也可以在struts.properties文件中完成. 1.<constant ...

  6. 微软推荐的130道ASP.NET常见面试题及答案

    1. 简述 private. protected. public. internal 修饰符的访问权限. 答 . private : 私有成员, 在类的内部才可以访问. protected : 保护成 ...

  7. android使用xfire webservice框架远程对sqlserver操作(包括增删改查)的实例!!已在真机上试验通过

    前两天,公司有一个利用android远程操作sqlserver的项目,对此我是毫无头绪的,但也挺感兴趣的,于是开始上网搜索方法,网上有挺多方法了,发现使用webservice的挺多的,不过我对这些技术 ...

  8. c/c++ 动态申请数组

    new和delete运算符用于动态分配和撤销内存的运算符 new使用方法: 1.     开辟单变量地址空间 1)new int;  //开辟一个存放数组的存储空间,返回一个指向该存储空间的地址.in ...

  9. Spring2.5学习3.3_@Autowire注解实现手动装配

    @Autowired默认按类型装配,假设我在personDao 字段上加了@Autowired注解,那么就会默认取personDao 字段的类型在Spring容器中寻找与这个类型匹配的bean,寻找到 ...

  10. uva 11732 - strcmp() Anyone? 不错的Trie题

    题解:http://blog.csdn.net/u013480600/article/details/23122503 我的代码一直TLE,,,看了人家的之后,认为1.链式前向星比較好,2.*dept ...