awsmpshk

Задача про вагоны и тупики, Кузичкин 141 группа

May 20th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.73 KB | None | 0 0
  1. #include <stack>
  2. #include <fstream>
  3.  
  4. struct Res
  5. {
  6.     char cart;
  7.     int way;
  8. };
  9.  
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14.     ifstream in("input.txt");
  15.     ofstream out("output.txt");
  16.     stack<char> сarts;
  17.     while (in.peek() != ' ')
  18.     {
  19.         char c;
  20.         in >> c;
  21.         carts.push(c);
  22.     }
  23.     stack<char> way1;
  24.     stack<char> way2;
  25.     int n;
  26.     in >> n;
  27.     while (in.peek() != EOF)
  28.     {
  29.         Res obj;
  30.         int c1 = 0;
  31.         int c2 = 0;
  32.         for (int i = 0; i < n; i++)
  33.         {
  34.             in >> obj.cart >> obj.way;
  35.             while (carts.top() != obj.cart)
  36.             {
  37.                 if (obj.way == 1)
  38.                 {
  39.                     char c = carts.top();
  40.                     carts.pop();
  41.                     way2.push(c);
  42.                     c2++;
  43.                 }
  44.                 else
  45.                 {
  46.                     char c = carts.top();
  47.                     carts.pop();
  48.                     way1.push(c);
  49.                     c1++;
  50.                 }
  51.             }
  52.             if (obj.way == 1)
  53.             {
  54.                 char c = carts.top();
  55.                 carts.pop();
  56.                 way1.push(c);
  57.             }
  58.             else
  59.             {
  60.                 char c = carts.top();
  61.                 carts.pop();
  62.                 way2.push(c);
  63.             }
  64.             if (c1 != 0)
  65.             {
  66.                 for (int i = 0; i < count1; i++)
  67.                 {
  68.                     char c = way1.top();
  69.                     way1.pop();
  70.                     carts.push(c);
  71.                 }
  72.                 c1 = 0;
  73.             }
  74.             if (c2 != 0)
  75.             {
  76.                 for (int i = 0; i < count2; i++)
  77.                 {
  78.                     char c = way2.top();
  79.                     way2.pop();
  80.                     carts.push(c);
  81.                 }
  82.                 c2 = 0;
  83.             }
  84.             stack<char> carttemp = carts;
  85.             stack<char> tmpway1 = way1;
  86.             stack<char> tmpway2 = way2;
  87.             while (!tmpway1.empty())
  88.             {
  89.                 char c = tmpway1.top();
  90.                 tmpway1.pop();
  91.                 out << c << ' ';
  92.             }
  93.             out << endl;
  94.             while (!tmpway2.empty())
  95.             {
  96.                 char c = tmpway2.top();
  97.                 tmpway2.pop();
  98.                 out << c << ' ';
  99.             }
  100.             out << endl;
  101.             while (!carttemp.empty())
  102.             {
  103.                 char c = carttemp.top();
  104.                 carttemp.pop();
  105.                 out << c << ' ';
  106.             }
  107.             out << endl << endl;
  108.             n--;
  109.         }
  110.         if (n == 0) break;
  111.     }
  112.     in.close();
  113.     out.close();
  114.     return 0;
  115. }
Add Comment
Please, Sign In to add comment