Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <stack>
  3. #include <string>
  4. #include <cstring>
  5. using namespace std;
  6.  
  7. bool f(string s){
  8. stack <char> sym;
  9. for (int i = 0; i < s.strlen(), i++) {
  10. if (s[i] == '(' || s[i] == '{' || s[i] == '['){
  11. sym.push(s[i]);
  12. }
  13. else{
  14. if (s[i] == ')' && sym.top() == '('){
  15. sym.pop();
  16. }
  17. else{
  18. return False;
  19. }
  20. }
  21. else if{
  22. if (s[i] == ']' && sym.top() == '[') {
  23. sym.pop();
  24. }
  25. else{
  26. return False;
  27. }
  28. }
  29. else if {
  30. if (s[i] == '}' && sym.top() == '{') {
  31. sym.pop();
  32. } else {
  33. return False;
  34. }
  35. }
  36. }
  37. return sym.lenght();
  38.  
  39. }
  40. string s;
  41. cin >> s;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement