-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlec6_9.cpp
68 lines (52 loc) Β· 1.17 KB
/
lec6_9.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//{ Driver Code Starts
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
// User function template for C++
class Solution {
public:
vector<int> bracketNumbers(string S) {
// Your code goes here
int count = 0 ;
stack<int>st;
vector<int>ans;
for(int i = 0 ;i<S.size();i++)
{
// opening bracket
if(S[i]=='(')
{
count++;
st.push(count);
ans.push_back(count);
}
//closing bracket
else if( S[i] == ')')
{
ans.push_back(st.top());
st.pop();
}
}
return ans;
}
};
//{ Driver Code Starts.
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int t;
string tc;
getline(cin, tc);
t = stoi(tc);
while (t--) {
string s;
getline(cin, s);
Solution ob;
vector<int> ans = ob.bracketNumbers(s);
for (auto i : ans)
cout << i << " ";
cout << "\n";
}
return 0;
}
// } Driver Code Ends