![]()
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 }
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(scanf("%d",&num)!=EOF)
18 {
19 cnt=0;
20 arry[cnt++] = num;
21 while (1)
22 {
23 scanf("%d", &num);
24 ch = getchar();
25 arry[cnt++] = num;
26 if (ch == '\n')
27 {
28 break;
29 }
30 }
31 for (int i = 0; i < ((cnt-1) / 2) * 2 ; i++, i++)
32 {
33 for (int j = ((cnt - 1) / 2) * 2 - 2; j >= i; j--, j--)
34 {
35 if (arry[j]>arry[j + 2])
36 {
37 int tmp;
38 tmp = arry[j];
39 arry[j] = arry[j + 2];
40 arry[j + 2] = tmp;
41 }
42 }
43 }
44 for (int m = 1; m < (cnt - 1) + ((cnt - 1) % 2) - 1; m++, m++)
45 {
46 for (int n = (cnt - 1) + ((cnt - 1) % 2) - 3; n >= m; n--, n--)
47 {
48 if (arry[n]<arry[n + 2])
49 {
50 int tmp;
51 tmp = arry[n];
52 arry[n] = arry[n + 2];
53 arry[n + 2] = tmp;
54 }
55 }
56 }
57
58 for (int k = 0; k < cnt; k++)
59 {
60 cout << arry[k]<<' ';
61 }
62 cout << endl;
63 }
64
65 return 0;
66 }