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

SWUST OJ #580 The World Population Explosion C++实现,第1张

题目描述:

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

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/741110.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-04-28
下一篇2022-04-28

发表评论

登录后才能评论

评论列表(0条)