質問編集履歴
1
コード修正追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -44,4 +44,45 @@
|
|
44
44
|
}
|
45
45
|
}
|
46
46
|
|
47
|
+
```
|
48
|
+
|
49
|
+
#修正後
|
50
|
+
```
|
51
|
+
#include <bits/stdc++.h>
|
52
|
+
using namespace std;
|
53
|
+
|
54
|
+
int main() {
|
55
|
+
int abcd;
|
56
|
+
cin >> abcd;
|
57
|
+
vector<int> ticket(4);
|
58
|
+
|
59
|
+
for(int i = 3; i > -1; i--){
|
60
|
+
ticket[i] = (abcd%10); // 1桁取り出していく
|
61
|
+
abcd /= 10;
|
62
|
+
}
|
63
|
+
|
64
|
+
for(int bit = 0; bit < (1 << 3); bit++){
|
65
|
+
int ans = ticket[0];
|
66
|
+
|
67
|
+
for(int idx = 0; idx < 3; idx++){
|
68
|
+
if(bit & (1 << idx)) ans += ticket[idx + 1];
|
69
|
+
|
70
|
+
else ans -= ticket[idx + 1];
|
71
|
+
}
|
72
|
+
|
73
|
+
if(ans == 7){
|
74
|
+
cout << ticket[0];
|
75
|
+
|
76
|
+
for(int idx = 0; idx < 3; idx++){
|
77
|
+
if(bit & (1 << idx)) cout << '+';
|
78
|
+
else cout << '-';
|
79
|
+
|
80
|
+
cout << ticket[idx + 1];
|
81
|
+
}
|
82
|
+
|
83
|
+
cout << "=7" << endl;
|
84
|
+
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
47
88
|
```
|