Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- using namespace std;
- int main() {
- string str;
- cin >> str;
- stack<char> openBrackets;
- for (char c : str) {
- if (c == '(' || c == '[' || c == '{') {
- openBrackets.push(c);
- }
- else if (openBrackets.size() == 0 ||
- c == ')' && openBrackets.top() != '(' ||
- c == ']' && openBrackets.top() != '[' ||
- c == '}' && openBrackets.top() != '{') {
- cout << "NO\n";
- return 0;
- }
- else {
- openBrackets.pop();
- }
- }
- cout << "YES\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement