Advertisement
Guest User

Untitled

a guest
Feb 5th, 2024
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stack>
  4. using namespace std;
  5. int main()
  6. {
  7. string s;
  8. cin >> s;
  9. string otkr = "([{<";
  10. string zakr = ")]}>";
  11. int n = s.length();
  12. stack <char> st;
  13. bool f = true;
  14. for (int i = 0; i < n; i++){
  15. if (otkr.find(s[i]) != -1)
  16. st.push(s[i]);
  17. if (zakr.find(s[i]) != -1){
  18. if (st.empty()){
  19. f = false;
  20. break;
  21. }
  22. if (zakr.find(s[i]) == otkr.find(st.top()))
  23. st.pop();
  24. else{
  25. f = false;
  26. break;
  27. }
  28. }
  29. }
  30. if (st.empty() && f)
  31. cout << "da";
  32. else
  33. cout << "net";
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement