Advertisement
Adrita

task 9( ds lab 4) 3rd sem

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