Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- string a;
- cin>> a;
- stack <char> st;
- for(int i=0; i<a.size(); i++)
- {
- if(a[i]=='(')
- {
- st.push(a[i]);
- }
- else if(a[i]==')')
- {
- if(st.empty() || st.top()==')')
- {
- st.push(a[i]);
- }
- else if(st.top()=='(')
- {
- st.pop();
- }
- }
- }
- cout<<st.size();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement