-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2504.cpp
54 lines (45 loc) · 909 Bytes
/
2504.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
//
// Created by vkdne on 2018-03-13.
//
#include <iostream>
#include <stack>
#include <string>
using namespace std;
string str;
stack<char> st;
int main(){
cin >> str;
int sol = 0;
int mul = 1;
for(int i = 0 ; i < str.length() ; i++){
if(str[i] == '['){
mul *= 3;
st.push(str[i]);
}
else if(str[i] == '('){
mul *= 2;
st.push(str[i]);
}
else if(str[i] == ']'){
if(str[i-1] == '['){
sol += mul;
}
if(st.top() == '[')
st.pop();
mul /= 3;
}
else{
if(str[i-1] == '('){
sol += mul;
}
if(st.top() == '(')
st.pop();
mul /= 2;
}
}
if(st.empty())
cout << sol;
else
cout << '0';
return 0;
}