Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <list>
- using namespace std;
- //Перезагрузил решение для зелёной галочки
- int main() {
- string path = "input.txt";
- ifstream file(path);
- if (!file.is_open()) {
- cout << "Error opening file!" << endl;
- return 1;
- }
- int count, n;
- count = 0;
- string nAsString;
- file >> nAsString;
- n = stoi(nAsString);
- list<string> left, right;
- string sign, number;
- while (count < n) {
- count++;
- file >> sign;
- if (sign == "+") {
- file >> number;
- right.push_back(number);
- } else if (sign == "*") {
- file >> number;
- right.push_front(number);
- } else if (sign == "-") {
- cout << left.front() << endl;
- left.pop_front();
- }
- if (left.size() < right.size()) {
- left.push_back(right.front());
- right.pop_front();
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment