11#include < iostream>
22using namespace std ;
33
4- int input[4 ], process[4 ], operator [3 ], cnt = 0 ; // Operators: 0 - add, 1 - subtract, 2 - multiply, 3 - divide
5- bool visit[13 ];
4+ int input[4 ], process[4 ], cnt = 0 ;
5+ int op[3 ]; // Operators: 0 - add, 1 - subtract, 2 - multiply, 3 - divide
6+ bool visit[4 ];
67
78void number_dfs (int t);
89void operator_dfs (int t);
@@ -21,10 +22,10 @@ void number_dfs(int t) {
2122 }
2223
2324 for (int i = 0 ; i < 4 ; i++) {
24- if (!visit[input[i] ]) {
25- process[t] = input[i]; visit[input[i] ] = true ;
25+ if (!visit[i ]) {
26+ process[t] = input[i]; visit[i ] = true ;
2627 number_dfs (t + 1 );
27- visit[input[i] ] = false ;
28+ visit[i ] = false ;
2829 }
2930 }
3031}
@@ -35,15 +36,15 @@ void operator_dfs(int t) {
3536 return ;
3637 }
3738 for (int i = 0 ; i < 4 ; i++) {
38- operator [t] = i;
39+ op [t] = i;
3940 operator_dfs (t + 1 );
4041 }
4142}
4243
4344void caculate () {
4445 int res = process[0 ];
4546 for (int i = 0 ; i < 3 ; i++) {
46- switch (operator [i]) {
47+ switch (op [i]) {
4748 case 0 : res += process[i + 1 ]; break ;
4849 case 1 : res -= process[i + 1 ]; break ;
4950 case 2 : res *= process[i + 1 ]; break ;
@@ -53,7 +54,7 @@ void caculate() {
5354 if (res == 24 ) {
5455 for (int i = 0 ; i < 3 ; i++) {
5556 cout << process[i] << " " ;
56- switch (operator [i]) {
57+ switch (op [i]) {
5758 case 0 : cout << " + " ; break ;
5859 case 1 : cout << " - " ; break ;
5960 case 2 : cout << " * " ; break ;
0 commit comments