标签:
1 #include "stdafx.h" 2 3 #include <stdio.h> 4 #include<iostream> 5 6 using namespace std; 7 8 #define length 100 9 10 int arry[length] = { 0 }; 11 int num; 12 char ch; 13 int cnt = 0; 14 15 int main(void) 16 { 17 while (1) 18 { 19 scanf_s("%d", &num); 20 ch = getchar(); 21 arry[cnt++] = num; 22 if (ch == ‘\n‘) 23 { 24 break; 25 } 26 } 27 for (int i = 0; i < ((cnt-1) / 2) * 2 ; i++, i++) 28 { 29 for (int j = ((cnt - 1) / 2) * 2 - 2; j >= i; j--, j--) 30 { 31 if (arry[j]>arry[j + 2]) 32 { 33 int tmp; 34 tmp = arry[j]; 35 arry[j] = arry[j + 2]; 36 arry[j + 2] = tmp; 37 } 38 } 39 } 40 for (int i = 1; i < (cnt - 1) + ((cnt - 1) % 2) - 1; i++, i++) 41 { 42 for (int j = (cnt - 1) + ((cnt - 1) % 2) - 3; j >= i; j--, j--) 43 { 44 if (arry[j]<arry[j + 2]) 45 { 46 int tmp; 47 tmp = arry[j]; 48 arry[j] = arry[j + 2]; 49 arry[j + 2] = tmp; 50 } 51 } 52 } 53 54 for (int i = 0; i < cnt; i++) 55 { 56 cout << arry[i]<<‘ ‘; 57 } 58 cout << endl; 59 return 0; 60 }
标签:
原文地址:http://www.cnblogs.com/hhboboy/p/5376536.html