Advertisement
makshev1

Untitled

Apr 20th, 2021
595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void next_step (int* const a, int* const b, char const * const msg) {
  5.     (*a)--; (*b)--; cout << msg << '-' << endl;
  6. }
  7.  
  8. int main() {
  9.     int A, B, C, D, E, F, G, H;
  10.     cin >> A >> B >> C >> D >> E >> F >> G >> H;
  11.  
  12.     if ((E + D + B + G) - (A + C + F + H) != 0) {
  13.         cout << "IMPOSSIBLE" << endl;
  14.         return 0;
  15.     }
  16.  
  17.     while (E + D + B + G > 0) {
  18.  
  19.         if (E > 0) {
  20.             if (A > 0) next_step(&E, &A, "EA");
  21.             else if (F > 0) next_step(&E, &F, "EF");
  22.             else if (H > 0)  next_step(&E, &H, "EH");
  23.             else if (C > 0) { E--; C--; cout << "FB+" << endl << "EF-" << endl << "CB-" << endl; }
  24.         }
  25.         if (D > 0) {
  26.             if (A > 0) next_step(&D, &A, "DA");
  27.             else if (C > 0) next_step(&D, &C, "DC");
  28.             else if (H > 0) next_step(&D, &H, "DH");
  29.             else if (F > 0) { D--; F--; cout << "EA+" << endl << "FE-" << endl << "DA-" << endl; }
  30.         }
  31.         if (B > 0) {
  32.             if (A > 0) next_step(&B, &A, "BA");
  33.             else if (C > 0) next_step(&B, &C, "BC");
  34.             else if (F > 0) next_step(&B, &F, "BF");
  35.             else if (H > 0) { B--; H--; cout << "EA+" << endl << "BA-" << endl << "EH-" << endl; }
  36.         }
  37.         if (G > 0) {
  38.             if (H > 0) next_step(&G, &H, "GH");
  39.             else if (C > 0) next_step(&G, &C, "GC");
  40.             else if (F > 0) next_step(&G, &F, "GF");
  41.             else if (A > 0) { G--; A--; cout << "FB+" << endl << "GF-" << endl << "AB-" << endl; }
  42.         }
  43.     }
  44.  
  45.     return 0;
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement