-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1068.cpp
74 lines (60 loc) · 947 Bytes
/
1068.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
69
70
71
72
73
74
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
struct parent{
char parenthese;
int pos;
};
int main()
{
int test_case;
stack<struct parent> s;
cin >> test_case;
while (test_case --)
{
int n;
vector<char> list;
cin >> n;
int last = 0;
for (int i = 0; i < n; ++ i)
{
int temp;
cin >> temp;
int len = temp - last;
for (int j = 0; j < len; ++ j)
{
list.push_back('(');
}
list.push_back(')');
last = temp;
}
for (int i = 0; list[i]; ++ i)
{
if (list[i] == '(')
{
struct parent p;
p.parenthese = '(';
p.pos = i;
s.push(p);
}
if (list[i] == ')')
{
struct parent p;
p = s.top();
int count = 0;
for (int j = p.pos; j <= i; ++ j)
{
if (list[j] == ')')
++ count;
}
if (!list[i + 1])
cout << count;
else
cout << count << " ";
s.pop();
}
}
cout << endl;
}
}