Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- apsed: 90:35:07RunningRemaining: 05:24:52
- Overview
- Problem
- Status
- Rank (90:35:03)
- 0 Comments
- Previous12345β¦Next
- Username
- Prob
- Result
- Time
- (ms) Mem
- (MB) Lang
- Submit Time
- Rat_rex
- A
- Accepted
- 40
- C++
- 2 days ago
- All Copyright Reserved Β© 2010-2020 Xu Han
- Server Time: 2020-01-26 12:35:08 BST
- #23829771 | Rat_rex's solution for [Problem A]
- Status
- Accepted
- Time
- 40ms
- Length
- 1414
- Lang
- C++11 5.3.0
- Submitted
- 2020-01-24 23:30:23
- Shared
- Select Code
- #include <bits/stdc++.h>
- using namespace std;
- int Priority(char c)
- {
- if (c == '(')
- return 1;
- if (c == '+' or c == '-')
- return 2;
- if (c == '*' or c == '/')
- return 3;
- }
- int main()
- {
- int t;
- int count = 0;
- cin >> t;
- cin.ignore();
- cin.ignore();
- while (t--)
- {
- string ss = "";
- string str;
- stack<char> st;
- while (1)
- {
- getline(cin, str);
- char ch = str[0];
- if (str.size() == 0 || !cin)
- break;
- if (isdigit(ch))
- {
- ss += ch;
- }
- else if (ch == '+' or ch == '-' or ch == '/' or ch == '*')
- {
- while (!st.empty() and Priority(ch) <= Priority(st.top()))
- {
- ss += st.top();
- st.pop();
- }
- st.push(ch);
- }
- else if (ch == ')')
- {
- while (st.top() != '(')
- {
- ss += st.top();
- st.pop();
- }
- st.pop();
- }
- else if (ch == '(')
- st.push('(');
- }
- while (!st.empty())
- {
- ss += st.top();
- st.pop();
- }
- cout << ss << endl;
- if (t)
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement