Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. std::string reverseParentheses(std::string s) {
  2.     std::stack<std::string> str;
  3.     str.push(std::string());
  4.    
  5.     for (char c : s) {
  6.         if (c == '(')
  7.             str.push(std::string());
  8.         else if (c == ')') {
  9.             std::string newS = str.top();
  10.             std::reverse(newS.begin(), newS.end());
  11.            
  12.             str.pop();
  13.             str.top() += newS;
  14.         }
  15.         else
  16.             str.top() += c;
  17.     }
  18.    
  19.     return str.top();
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement