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. response.sendRedirect("")和request.getRequestDispatcher("").forward(req,resp);

    1:request.getRequestDispatcher("转发路径").forward(req,resp)该语句是实现请求转发的,当请求进入到该servlet中执行到该语句时 ...

  2. c语言, objective code(new 2)

    参考: 1. C中的继承和多态 http://www.cnblogs.com/skynet/archive/2010/09/23/1833217.html

  3. Exchange Server 2013传输规则之全新附件限制

  4. Qt Creator键盘快捷键速查

    原地址:http://bbs.qter.org/forum.php?mod=viewthread&tid=904&extra=page%3D2 一般操作的键盘快捷键 操作 快捷键 操作 ...

  5. TinkPHP+WAMP

    1.下载wamp 我下载的是php5.5版本:根据你自身的需要嘛 http://www.wampserver.com/ 2.下载thinkphp 我下载的版本是3.2 http://www.think ...

  6. mysql存储过程及经常使用函数

    一.函数 1.数学函数 CEIL()进一取整 SELECT CEIL(1.2);2 FLOOR()舍一取整 SELECT FLOOR(1.9);9 MOD取余数(取模) SELECT MOD(3,8) ...

  7. UVA 839 (13.08.20)

     Not so Mobile  Before being an ubiquous communications gadget, a mobile wasjust a structure made of ...

  8. Oracle Autonomous Transactions(自治事务)

    Oracle Autonomous Transactions Autonomous transactions allow you to leave the context of the calling ...

  9. Swift - 异步获取网络数据封装类

    使用NSURLConnection.sendAsynchronousRequest()可以采用异步获取的方式取得数据.下面通过对数据获取类进行封装,演示如何进行数据请求与接收. 1,HttpContr ...

  10. [置顶] 关于redhat系统yum源的配置2

    (二)配置yum源(官方) 1.在终端输入以下命令(RHEL6/CentOS6) wget http://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/ ...