奇偶对调,n个数以内
#include void main() { int a[100], b[100], n, i, j, temp; int ji = 0; int ou = 0; int count = 0; scanf("%d", &n); for (i = 0; i != n; ++i) { scanf("%d", &a[i]); if (a[i] % 2 == 0) { count++; } } ji = count; for (i = 0; i != n; ++i) { if (a[i] % 2 == 0) { b[ou] = a[i]; ou++; } else { b[ji] = a[i]; ji++; } } for (i = 0; i != count; ++i) { for (j = i; j != count; ++j) { if (b[i] < b[j]) { temp = b[i]; b[i] = b[j]; b[j] = temp; } } } for (i = count; i != n; ++i) { for (j = count; j != n; ++j) { if (b[i] > b[j]) { temp = b[i]; b[i] = b[j]; b[j] = temp; } } } for (i = 0; i != n; ++i) { printf("%d ", b[i]); } printf("\n"); } = a[i]; ou++; } else { b[ji] = a[i]; ji++; } } for (i = 0; i != count; ++i) { for (j = i; j != count; ++j) { if (b[i] < b[j]) { temp = b[i]; b[i] = b[j]; b[j] = temp; } } } for (i = count; i != n; ++i) { for (j = count; j != n; ++j) { if (b[i] > b[j]) { temp = b[i]; b[i] = b[j]; b[j] = temp; } } } for (i = 0; i != n; ++i) { printf("%d ", b[i]); } printf("\n"); }
用户评论