Advertisement
chzchz

Untitled

Mar 25th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <deque>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     deque<string> result;
  9.     string first_value;
  10.  
  11.     cin >> first_value;
  12.     result.push_back(first_value);
  13.  
  14.     size_t quantity_of_operations;
  15.     cin >> quantity_of_operations;
  16.  
  17.     for (size_t i = 0; i <= quantity_of_operations; ++i) {
  18.         string current;
  19.         getline(cin, current);
  20.  
  21.         auto previous = result.back();
  22.  
  23.         if ((previous[1] == ' ') &&
  24.             (previous[0] == '+' || previous[0] == '-') &&
  25.             (current[0] == '*' || current[0] == '/')) {
  26.             result.push_front("(");
  27.             result.push_back(") ");
  28.             result.push_back(current);
  29.         } else if (i != 0) {
  30.             result.push_back(" ");
  31.             result.push_back(current);
  32.         }
  33.     }
  34.  
  35.     for (const auto &item : result) {
  36.         cout << item;
  37.     }
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement