Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <fstream>
- 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 = 0;
- string nAsString;
- int n;
- file >> nAsString;
- n = stoi(nAsString);
- vector<string> goblins;
- string sign;
- string number;
- while (count < n) {
- count++;
- file >> sign;
- if (sign == "+") {
- file >> number;
- goblins.push_back(number);
- } else if (sign == "*") {
- file >> number;
- if (goblins.size() % 2 == 0) {
- goblins.insert(goblins.begin() + goblins.size() / 2, number);
- } else {
- goblins.insert(goblins.begin() + 1 + goblins.size() / 2, number);
- }
- } else if (sign == "-") {
- cout << goblins.front() << endl;
- goblins.erase(goblins.begin());
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement