-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1155.cpp
69 lines (63 loc) · 1.75 KB
/
1155.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
using namespace std;
struct Point{
char ch;
int n;
};
void minus_p(Point* x, Point* y) {
--(x->n);
--(y->n);
cout << y->ch << x->ch << '-' << endl;
};
void plus_p(Point* x, Point* y) {
++(x->n);
++(y->n);
cout << y->ch << x->ch << '+' << endl;
};
int main() {
Point a = {'A'}, b = {'B'}, c = {'C'}, d = {'D'}, e = {'E'}, f = {'F'}, g = {'G'}, h = {'H'};
cin >> a.n >> b.n >> c.n >> d.n >> e.n >> f.n >> g.n >> h.n;
if (a.n + c.n + f.n + h.n != b.n + d.n + e.n + g.n) {
cout << "IMPOSSIBLE" << endl;
return 0;
}
while (a.n + c.n + f.n + h.n > 0) {
if (a.n > 0) {
if (b.n > 0) minus_p (&a, &b);
else if (d.n > 0) minus_p(&a, &d);
else if (e.n > 0) minus_p(&a, &e);
else if (g.n > 0) {
plus_p(&f,&b);
minus_p (&a, &b);
}
}
else if (h.n > 0) {
if (g.n > 0) minus_p(&h, &g);
else if (e.n > 0) minus_p(&h, &e);
else if (d.n > 0) minus_p(&h, &d);
else if (b.n > 0) {
plus_p(&d,&c);
minus_p(&h, &d);
}
}
else if (f.n > 0) {
if (b.n > 0) minus_p(&f, &b);
else if (e.n > 0) minus_p(&f, &e);
else if (g.n > 0) minus_p(&f, &g);
else if (d.n > 0) {
plus_p(&a,&b);
minus_p(&f, &b);
}
}
else if (c.n > 0) {
if (g.n > 0) minus_p(&c, &g);
else if (d.n > 0) minus_p(&c, &d);
else if (b.n > 0) minus_p(&b, &c);
else if (e.n > 0) {
plus_p(&f,&b);
minus_p(&b, &c);
}
}
}
return 0;
}