Print out the order number of opening and closing parenthesis in a string For example "((())(()))" the output should be "1 2 3 3 2 4 5 5 4 1"
means that "1st openning parenthesis, 2nd openning, 3rd openning, 3rd openning's closing parenthesis, 2nd openning's closing, 4th openning,..." and so on
I've tried using stack but have no idea what to do after the first closing parenthesis i hit
This is what i have so far
#include <bits/stdc++.h>
using namespace std;
void check(string s){
stack<char> a;
char ch[s.length()];
int done = 0;
for (char tmp : ch){
if (tmp == '('){
a.push(tmp);
cout<<a.size() + done<<" ";
}
if(tmp == ')'){
a.pop();
done++;
cout<<a.size() + done<<" ";
}
}
}
main(){
string s;
getline(cin, s);
check(s);
}