标签:print mil pac swap col == ace pre printf
把数组中所有的奇数放到偶数的左边不在意顺序
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int N; int a[maxn]; int main() { scanf("%d", &N); for(int i = 0; i < N; i ++) scanf("%d", &a[i]); int l = 0, r = N - 1; while(l <= r) { if(a[l] % 2 == 0) { while(a[r] % 2 == 0 && r > l) r --; swap(a[l], a[r]); } l ++; } for(int i = 0; i < N; i ++) printf("%d\n", a[i]); return 0; }
标签:print mil pac swap col == ace pre printf
原文地址:https://www.cnblogs.com/zlrrrr/p/13277451.html