Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- #include <string>
- using namespace std;
- int main() {
- stack <char> S;
- char ch;
- string line;
- getline(cin, line);
- for (int i = 0; line[i]; i++) {
- if (line[i] == ' ')
- continue;
- else if (line[i] == '(' || line[i] == '+' || line[i] == '-' || line[i] == '*' || line[i] == '/' || line[i] == '%' || line[i] == '^')
- S.push(line[i]);
- else if (line[i] == ')') {
- while (S.top() != '(') {
- cout << S.top() << " ";
- S.pop();
- }
- S.pop();
- }
- else
- cout << line[i] << " ";
- }
- while (!S.empty()) {
- ch = S.top();
- if (ch != '(')
- cout << ch << " ";
- S.pop();
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement