文章

60

粉丝

361

获赞

41

访问

498.0k

头像
亢龙有悔
P1248 北京大学机试题
发布于2021年1月13日 09:23
阅读数 7.3k

#include <iostream>
#include <string>
#include <string.h>
#include<algorithm>
using namespace std;

bool compare(int a,int b)
{
	if(a%2&&b%2)//都是奇数
		return a>b;
	else if(a%2==0&&b%2==0)//偶数
		return a<b;
	else//奇偶
		return (a%2>b%2);

}
int main()
{

	int a[10];
	while(cin>>a[0])
	{
		for(int i=1;i<10;i++)
			cin>>a[i];
		sort(a,a+10,compare);
		for(int i=0;i<10;i++)
			cout<<a[i]<<" ";
		cout<<endl;
	}
	system("pause");
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发