1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| #include <bits/stdc++.h> using namespace std; const int maxn = 15; int a[maxn]; int b[maxn]; void bubble_sort1(int l, int r) { for (int i = 0; i < r - l + 1; ++i) { for (int j = l; j < r; ++j) { if (b[j] > b[j + 1]) { swap(b[j], b[j + 1]); } } } } void bubble_sort2(int l, int r) { for (int i = 0; i < r - l + 1; ++i) { for (int j = l; j < r; ++j) { if (b[j] < b[j + 1]) { swap(b[j], b[j + 1]); } } } } signed main() { for (int i = 0; i < 10; ++i) { cin >> a[i]; } int p1 = 0, p2 = 9; for (int i = 0; i < 10; ++i) { if (a[i] % 2 == 0) { b[p2] = a[i]; p2--; } else { b[p1] = a[i]; p1++; } } bubble_sort2(0, p1 - 1); bubble_sort1(p1, 9); for (int i = 0; i < 10; ++i) cout << b[i] << " "; cout << endl; return 0; }
|