-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
140 lines (128 loc) · 1.97 KB
/
main.c
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
void iterSeq(int* in, int cnt)
{
//0 1 2 3
//0 1 3 2
//0 2 1 3
//0 2 3 1
//0 3 1 2
//0 3 2 1
//1 0 2 3
//1 0 3 2
//1 2 0 3
//1 2 3 0
//1 3 0 2
//1 3 2 0
for (int i = cnt- 1;i>0;i--)
{
for( int j=i-1;j>=0;j--)
{
if (in[i] > in[j])
{
int tmp = in[i];
in[i] = in[j];
in[j] = tmp;
sort(in+j+1, cnt-j-1);
return;
}
}
}
}
void sort(int* in, int cnt)
{
for(int i = 0;i<cnt-1;i++)
{
for(int j=i+1;j<cnt;j++)
{
if (in[i] < in[j])
{
int tmp=in[i];
in[i] = in[j];
in[j] = tmp;
}
}
}
for (int i = 0;i<cnt/2;i++)
{
int tmp = in[i];
in[i] = in[cnt - 1 -i];
in[cnt - 1 - i] = tmp;
}
}
int getmin_pos(int* in, int cnt)
{
if (cnt == 0)
return 0;
int min_pos = 0;
for (int i = 0;i<cnt;i++)
{
if(in[i] < in[min_pos])
{
min_pos = i;
}
}
return min_pos;
}
int op(int in1, int in2, int op)
{
switch (op){
case 0:
return in1 + in2;
case 1:
return in1 - in2;
case 2:
return in1 * in2;
case 3:
if ( in1 % in2 != 0)
return 99999999;
else
return in1 / in2;
}
}
char itoa_op(int op)
{
switch (op){
case 0:
return '+';
case 1:
return '-';
case 2:
return 'x';
case 3:
return '/';
}
}
void main(int argc, char* argv[])
{
if (argc <=1 || argc !=5)
{
printf("input 4 number");
return;
}
int in[4];
in[0]=atoi(argv[1]);
in[1]=atoi(argv[2]);
in[2]=atoi(argv[3]);
in[3]=atoi(argv[4]);
sort(in,4);
for (int i=0;i<4*3*2;i++)
{
for(int ii=0;ii<4;ii++)
for(int iii=0;iii<4;iii++)
for(int iiii=0;iiii<4;iiii++)
{
int val1 = op(in[0],in[1],ii);
int val2 = op(val1,in[2],iii);
int val3 = op(val2,in[3],iiii);
if (val3 == 24)
{
printf("=======================%d %c %d %c %d %c %d= %d\n",in[0],itoa_op(ii),in[1],itoa_op(iii),in[2],itoa_op(iiii),in[3],val3);
}
}
iterSeq(in, argc-1);
printf("------------------%d %d %d %d\n",in[0],in[1],in[2],in[3]);
}
}