Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- using namespace std;
- int main() {
- char s;
- stack<char> ourstack;
- while (cin >> s && s != '#') {
- if (s == '(' || s == '{' || s == '[') {
- ourstack.push(s);
- } else if (s == ')' && ourstack.top() == '(') {
- ourstack.pop();
- } else if (s == '}' && ourstack.top() == '{') {
- ourstack.pop();
- } else if (s == ']' && ourstack.top() == '[') {
- ourstack.pop();
- } else { cout << "no"; return 0;}
- }
- if (!ourstack.empty()) {
- cout << "no";
- } else {
- cout << "yes";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement