Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. freopen("input.txt" , "r" , stdin);
  7. freopen("output.txt" , "w" , stdout);
  8. string s;
  9. while (cin >> s) {
  10. stack <char> st;
  11. for (int i = 0; i < s.size(); i++) {
  12. if (s[i] == '{' || s[i] == '[' || s[i] == '(') {
  13. st.push(s[i]);
  14. }
  15. else
  16. if ((s[i] == '}' && st.top() == '{') || (s[i] == ']' && st.top() == '[') || (s[i] == ')' && st.top() == '(')) {
  17. st.pop();
  18. }
  19. else
  20. st.push(s[i]);
  21. }
  22. if (st.empty()) {
  23. cout << 0;
  24. } else {
  25. cout << 1;
  26. }
  27. }
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement