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
75
|
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
stack<char> st;
if (s.size() % 2 == 1)
cout << 0 << '\n';
else
{
int res = 1, ans = 0;
bool flag = true;
for (int i = 0; i < s.size(); i++)
{
if (s[i] == '(')
{
st.push('(');
res *= 2;
}
if (s[i] == '[')
{
st.push('[');
res *= 3;
}
{
flag = false;
break;
}
if (s[i] == ']')
{
if (s[i - 1] == '[')
{
ans += res;
}
st.pop();
res /= 3;
}
{
flag = false;
break;
}
if (s[i] == ')')
{
if (s[i - 1] == '(')
{
ans += res;
}
st.pop();
res /= 2;
}
}
if (!flag)
cout << 0 << '\n';
else
cout << ans << '\n';
}
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
BOJ/C++