Advertisement
alsiva

DanyaЭтоДостаточноОтличается

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