栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

SWUST OJ #580 The World Population Explosion C++实现

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SWUST OJ #580 The World Population Explosion C++实现

题目描述:

In the past, when population grew, there was unexplored territory to inhabit. But now, almost all the habitable land has been explored. The world's population may reach 8.7 billion in 2033. It is clear that world population is a serious issue that needs careful attention. Human beings are unique to solve problems through cultural evolution. Facing the world population explosion in the near future, we must carry out the birth control program in order to save the mankind and save the world. And now we have the population amount of some country of the world in last year and this year. your task is to differ the countries whose population is changed from the data below and sort them in descending order and return the changing value and names of those countries whose population amount are not changed as well.

输入:

The input consists of only one test case, followed by 4 lines, the first line is a integer N indicating the amount of the countries, and then input last year’s and this year’s population amount of every country in the last two lines before the names of the countries is inputted in the second line.

输出:

You should output the countries firstly whose population are changed followed by the rest of those whose population are unchanged. If the changes are the same between two countries, lexicographic order should be used in your code.

样例输入

7
USA CHINA JAPAN KOREA CUBA ARGENTINA PERU
100 200 150 50 9 2 22
120 240 140 10 9 2 12

样例输出

40 CHINA
20 USA
-10 JAPAN
-10 PERU
-40 KOREA
0 ARGENTINA
0 CUBA

 代码

#include
using namespace std;
#include
#include 

class country{
	public:  
		string name;  //名字
		int last;  //去年人口
		int now;  //今年人口
		int s; //去年和今年的差
};
class mysort{ //仿函数,对正负和国名字符串排序
	public:
		bool operator ()(country a,country b)
		{
			if(a.s==b.s)
			{
				return a.nameb.s;
			}
		}
};

country zheng[200];
country fu[200];
country ling[200];
int z=0,f=0,l=0;

int main()
{
	int n;
	cin>>n;
	country arr[n];
	for(int i=0;i>arr[i].name;
	}
	
	for(int i=0;i>arr[i].last;
	}
	for(int i=0;i>arr[i].now;
	}
	for(int i=0;i0)
		{
			zheng[z]=arr[i];
			z++;
		}
		if(arr[i].s<0)
		{
			fu[f]=arr[i];
			f++;
		}
		if(arr[i].s==0)
		{
			ling[l]=arr[i];
			l++;
		}
	}
	sort(zheng,zheng+z,mysort());//排序
	sort(fu,fu+f,mysort());
	sort(ling,ling+l,mysort());
	for(int i=0;i 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/835535.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号