-
Notifications
You must be signed in to change notification settings - Fork 14
/
10344.cpp
47 lines (43 loc) · 923 Bytes
/
10344.cpp
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
#include <algorithm>
#include <cstdio>
using namespace std;
int func(int tot, int val, int I) {
switch (I) {
case 0: return (tot + val);
case 1: return (tot - val);
case 2: return (tot * val);
}
return 0;
}
int main() {
while (true) {
int num[5];
for (int i = 0; i < 5; i++)
scanf("%d", &num[i]);
if (count(num, num + 5, 0) == 5)
break;
bool flag = false;
sort(num, num + 5);
do {
for (int a = 0; a < 3; a++)
for (int b = 0; b < 3; b++)
for (int c = 0; c < 3; c++)
for (int d = 0; d < 3; d++) {
int tot = num[0];
tot = func(tot, num[1], a);
tot = func(tot, num[2], b);
tot = func(tot, num[3], c);
tot = func(tot, num[4], d);
if (tot == 23) {
flag = true;
break;
}
}
} while (next_permutation(num, num + 5));
if (flag)
printf("Possible\n");
else
printf("Impossible\n");
}
return 0;
}