Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- #include <string>
- #include <stdio.h>
- #include <set>
- #include <cstdio>
- using namespace std;
- #include <cstdio>
- using namespace std;
- int main() {
- char ch;
- stack<char> myStack;
- while (scanf("%c", &ch)) {
- if ((ch == '(') || (ch == '[') || (ch == '{')) {
- myStack.push(ch);
- } else if (ch == ')') {
- if ((myStack.size() == 0) || (myStack.top() != '(')) {
- cout << "no" << endl;
- return 0;
- } else {
- myStack.pop();
- }
- } else if (ch == ']') {
- if ((myStack.size() == 0) || (myStack.top() != '[')) {
- cout << "no" << endl;
- return 0;
- } else {
- myStack.pop();
- }
- } else if (ch == '}') {
- if ((myStack.size() == 0) || (myStack.top() != '{')) {
- cout << "no" << endl;
- return 0;
- } else {
- myStack.pop();
- }
- }
- }
- if (myStack.size() == 0) {
- cout << "yes" << endl;
- } else {}
- cout << "no" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement