文章

7

粉丝

319

获赞

5

访问

71.4k

头像
直接自定义排序即可,建议学学
P1010 兰州大学2018/贵州大学2018年机试
发布于2020年8月9日 13:10
阅读数 10.5k

#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
const int maxM = 1e6+10;
const int inf = 0x3f3f3f3f;

int N;
struct node
{
	int val;
	bool operator <(const node &o)const{
		if(val %2 == o.val%2) return val < o.val;
		else return (val&1)? true:false;
	}
}arr[maxn];
int main(){
	// debug;
	ios;

	cin>>N;
	for(int i = 1;i<=N;i++) cin>>arr[i].val;
	sort(arr+1,arr+N+1);
	for(int i = 1;i<=N;i++) cout<<arr[i].val<<" ";
	

	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发