Skip to content

Commit a8f36c3

Browse files
committed
add task 3
1 parent 3478054 commit a8f36c3

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

task_3_1155/1155.cpp

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
struct Point{
6+
char ch;
7+
int n;
8+
};
9+
10+
void minus_p(Point* x, Point* y) {
11+
--(x->n);
12+
--(y->n);
13+
cout << y->ch << x->ch << '-' << endl;
14+
};
15+
16+
void plus_p(Point* x, Point* y) {
17+
++(x->n);
18+
++(y->n);
19+
cout << y->ch << x->ch << '+' << endl;
20+
};
21+
22+
int main() {
23+
Point a = {'A'}, b = {'B'}, c = {'C'}, d = {'D'}, e = {'E'}, f = {'F'}, g = {'G'}, h = {'H'};
24+
cin >> a.n >> b.n >> c.n >> d.n >> e.n >> f.n >> g.n >> h.n;
25+
if (a.n + c.n + f.n + h.n != b.n + d.n + e.n + g.n) {
26+
cout << "IMPOSSIBLE" << endl;
27+
return 0;
28+
}
29+
30+
while (a.n + c.n + f.n + h.n > 0) {
31+
if (a.n > 0) {
32+
if (b.n > 0) minus_p (&a, &b);
33+
else if (d.n > 0) minus_p(&a, &d);
34+
else if (e.n > 0) minus_p(&a, &e);
35+
else if (g.n > 0) {
36+
plus_p(&f,&b);
37+
minus_p (&a, &b);
38+
}
39+
}
40+
else if (h.n > 0) {
41+
if (g.n > 0) minus_p(&h, &g);
42+
else if (e.n > 0) minus_p(&h, &e);
43+
else if (d.n > 0) minus_p(&h, &d);
44+
else if (b.n > 0) {
45+
plus_p(&d,&c);
46+
minus_p(&h, &d);
47+
}
48+
}
49+
else if (f.n > 0) {
50+
if (b.n > 0) minus_p(&f, &b);
51+
else if (e.n > 0) minus_p(&f, &e);
52+
else if (g.n > 0) minus_p(&f, &g);
53+
else if (d.n > 0) {
54+
plus_p(&a,&b);
55+
minus_p(&f, &b);
56+
}
57+
}
58+
else if (c.n > 0) {
59+
if (g.n > 0) minus_p(&c, &g);
60+
else if (d.n > 0) minus_p(&c, &d);
61+
else if (b.n > 0) minus_p(&b, &c);
62+
else if (e.n > 0) {
63+
plus_p(&f,&b);
64+
minus_p(&b, &c);
65+
}
66+
}
67+
}
68+
return 0;
69+
}

0 commit comments

Comments
 (0)