• 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;
    }


  • 相关阅读:
    gorm 更新数据时,0值会被忽略
    xshell评估过期解决办法
    安装zoom
    aria2 加速百度网盘下载
    ubuntu17.10 安装firefox的flash
    c++ 回调函数使用
    ubuntu17 安装中文输入法
    ubuntu python3.6 找不到_sqlite3
    linux 获取CPU个数
    centos7 yum与Python3冲突
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10678854.html
  • Copyright © 2020-2023  润新知