Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <deque>
- using namespace std;
- int main() {
- deque<string> result;
- string first_value;
- cin >> first_value;
- result.push_back(first_value);
- size_t quantity_of_operations;
- cin >> quantity_of_operations;
- for (size_t i = 0; i <= quantity_of_operations; ++i) {
- string current;
- getline(cin, current);
- auto previous = result.back();
- if ((previous[1] == ' ') &&
- (previous[0] == '+' || previous[0] == '-') &&
- (current[0] == '*' || current[0] == '/')) {
- result.push_front("(");
- result.push_back(") ");
- result.push_back(current);
- } else if (i != 0) {
- result.push_back(" ");
- result.push_back(current);
- }
- }
- for (const auto &item : result) {
- cout << item;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement