• PAT-B 1015. 德才论(同PAT 1062. Talent and Virtue)


    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
    ", 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
    ", 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;
    }


  • 相关阅读:
    内存溢出和内存泄漏的区别
    测试管理三要素(人员、过程和技术)
    面试可提问的6个问题
    弱网测试(二)
    js捕获错误
    TortoiseGit自动记住用户名密码的方法
    win7 "com surrogate“ 已停止工作的解决办法
    仿百度图片毛玻璃效果
    毛玻璃效果
    vimium快捷键列表
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10043004.html
Copyright © 2020-2023  润新知