Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <stack>
- using namespace std;
- int main() {
- string expression;
- getline(cin, expression);
- stack<int> openBracketIndexes;
- for (size_t i = 0; i < expression.length(); i++) {
- if (expression[i] == '(') {
- openBracketIndexes.push(i);
- }
- else if (expression[i] == ')') {
- cout << expression.substr(openBracketIndexes.top(), i - openBracketIndexes.top() + 1) << endl;
- openBracketIndexes.pop();
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement