Advertisement
firedigger

Untitled

Oct 8th, 2015
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. bool correct_parentheses(std::string seq)
  2. {
  3.     std::stack<char> x;
  4.     std::map<char, char> p;
  5.     p['('] = ')';
  6.     p['['] = ']';
  7.     for (auto t : seq)
  8.     {
  9.         if (t == '(' || t == '[')
  10.             x.push(t);
  11.         if (t == ')' || t == ']')
  12.         {
  13.             if (p[x.top()] == t)
  14.                 x.pop();
  15.             else
  16.                 return false;
  17.         }
  18.     }
  19.     return x.empty();
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement