Advertisement
alsiva

Alsiva_GoblinsAndQueues

Apr 18th, 2022
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. string path = "input.txt";
  9. ifstream file(path);
  10.  
  11. if (!file.is_open()) {
  12. cout << "Error opening file!" << endl;
  13. return 1;
  14. }
  15.  
  16. int count = 0;
  17. string nAsString;
  18. int n;
  19. file >> nAsString;
  20. n = stoi(nAsString);
  21.  
  22. vector<string> goblins;
  23. string sign;
  24. string number;
  25.  
  26.  
  27. while (count < n) {
  28.  
  29. count++;
  30. file >> sign;
  31.  
  32. if (sign == "+") {
  33. file >> number;
  34. goblins.push_back(number);
  35.  
  36. } else if (sign == "*") {
  37. file >> number;
  38.  
  39. if (goblins.size() % 2 == 0) {
  40. goblins.insert(goblins.begin() + goblins.size() / 2, number);
  41. } else {
  42. goblins.insert(goblins.begin() + 1 + goblins.size() / 2, number);
  43. }
  44.  
  45. } else if (sign == "-") {
  46. cout << goblins.front() << endl;
  47. goblins.erase(goblins.begin());
  48. }
  49.  
  50. }
  51.  
  52. return 0;
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement