Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <stack>
  3. #include <string>
  4. #include <cstring>
  5. using namespace std;
  6.  
  7. int main(){
  8. stack <char> sym;
  9. string s;
  10. getline(cin,s);
  11. int count = 0;
  12. for (auto c : s){
  13. if (c == '(' || c == '{' || c == '['){
  14. sym.push(c);
  15. }
  16. else if(c == ')'){
  17. if (sym.top() == '('){
  18. sym.pop();
  19. }
  20. else{
  21. count += 1;
  22. }
  23. }
  24. else if(c == ']'){
  25. if (sym.top() == '[') {
  26. sym.pop();
  27. }
  28. else{
  29. count += 1;
  30. }
  31. }
  32. else if(c == '}') {
  33. if ( sym.top() == '{') {
  34. sym.pop();
  35. }
  36. else {
  37. count += 1;
  38. }
  39. }
  40. }
  41. if (sym.empty() && count == 0){
  42. cout << "YES";
  43. }
  44. else{
  45. cout << "NO";
  46. }
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement