文章

59

粉丝

0

获赞

298

访问

6.5k

头像
排序 题解:vector+sort轻松解决
P1010 兰州大学/贵州大学机试
发布于2026年3月10日 00:30
阅读数 171

#include <bits/stdc++.h>
using namespace std;

bool cmp(const int &x,const int &y)
{
	if(x%2!=0&&y%2==0)
		return true;
	else if(x%2==0&&y%2!=0)
		return false;
	return x<y;
}
int main()
{
	int n;
	vector<int> list;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		list.push_back(x);
	}
	sort(list.begin(),list.end(),cmp);
	for(int i=0;i<n;++i)
		cout<<list[i]<<" ";
	cout<<endl;
	return 0;
}
	
	
	
	

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发