Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stack>
- #include <fstream>
- struct Res
- {
- char cart;
- int way;
- };
- using namespace std;
- int main()
- {
- ifstream in("input.txt");
- ofstream out("output.txt");
- stack<char> сarts;
- while (in.peek() != ' ')
- {
- char c;
- in >> c;
- carts.push(c);
- }
- stack<char> way1;
- stack<char> way2;
- int n;
- in >> n;
- while (in.peek() != EOF)
- {
- Res obj;
- int c1 = 0;
- int c2 = 0;
- for (int i = 0; i < n; i++)
- {
- in >> obj.cart >> obj.way;
- while (carts.top() != obj.cart)
- {
- if (obj.way == 1)
- {
- char c = carts.top();
- carts.pop();
- way2.push(c);
- c2++;
- }
- else
- {
- char c = carts.top();
- carts.pop();
- way1.push(c);
- c1++;
- }
- }
- if (obj.way == 1)
- {
- char c = carts.top();
- carts.pop();
- way1.push(c);
- }
- else
- {
- char c = carts.top();
- carts.pop();
- way2.push(c);
- }
- if (c1 != 0)
- {
- for (int i = 0; i < count1; i++)
- {
- char c = way1.top();
- way1.pop();
- carts.push(c);
- }
- c1 = 0;
- }
- if (c2 != 0)
- {
- for (int i = 0; i < count2; i++)
- {
- char c = way2.top();
- way2.pop();
- carts.push(c);
- }
- c2 = 0;
- }
- stack<char> carttemp = carts;
- stack<char> tmpway1 = way1;
- stack<char> tmpway2 = way2;
- while (!tmpway1.empty())
- {
- char c = tmpway1.top();
- tmpway1.pop();
- out << c << ' ';
- }
- out << endl;
- while (!tmpway2.empty())
- {
- char c = tmpway2.top();
- tmpway2.pop();
- out << c << ' ';
- }
- out << endl;
- while (!carttemp.empty())
- {
- char c = carttemp.top();
- carttemp.pop();
- out << c << ' ';
- }
- out << endl << endl;
- n--;
- }
- if (n == 0) break;
- }
- in.close();
- out.close();
- return 0;
- }
Add Comment
Please, Sign In to add comment