Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <stack>
  3. using namespace std;
  4.  
  5. int main() {
  6. char s;
  7. stack<char> ourstack;
  8. while (cin >> s && s != '#') {
  9. if (s == '(' || s == '{' || s == '[') {
  10. ourstack.push(s);
  11. } else if (s == ')' && ourstack.top() == '(') {
  12. ourstack.pop();
  13. } else if (s == '}' && ourstack.top() == '{') {
  14. ourstack.pop();
  15. } else if (s == ']' && ourstack.top() == '[') {
  16. ourstack.pop();
  17. } else { cout << "no"; return 0;}
  18.  
  19. }
  20. if (!ourstack.empty()) {
  21. cout << "no";
  22. } else {
  23. cout << "yes";
  24. }
  25. return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement