-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtoi16_packbot.cpp
More file actions
104 lines (88 loc) · 2.26 KB
/
toi16_packbot.cpp
File metadata and controls
104 lines (88 loc) · 2.26 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <bits/stdc++.h>
using namespace std;
stack<int>cost;
stack<char>st;
map<char,int>val;
int cal(int a,int b,int op){
// cout << a << " " << b << " OP " << op << endl;
int ret;
if(op == 1) ret = (a+b)*4/100 + a + b;
if(op == 2) ret = (a+b)*8/100 + a + b;
if(op == 3) ret = (a+b)*16/100 + a + b;
// cout << " = " << ret << endl;
return ret;
}
void kid(){
if(st.empty()) return;
char top = st.top();
st.pop();
int ctop = cost.top();
cost.pop();
if(st.empty() || val[st.top()] < val[top] || st.top() == '['){
st.push(top);
cost.push(ctop);
return;
}
while(!st.empty() && val[st.top()] >= val[top] && cost.size() >= 2){
if(st.top() == '[') break;
int a = cost.top();
cost.pop();
int b = cost.top();
cost.pop();
char op = st.top();
st.pop();
//cout << a << " " << b << endl;
cost.push(cal(a,b,val[op]));
}
cost.push(ctop);
st.push(top);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
string str;
cin >> str;
int si = str.size();
val['1'] = 1;
val['2'] = 2;
val['3'] = 3;
val['['] = 4;
for(int i = 0;i<si;i++){
//cout << st.size() << " , " << cost.size() << endl;
// cout << str[i] << endl;
if(str[i] >= 'A' && str[i] <= 'Z'){
// cout << "Push 20" << endl;
cost.push(20);
kid();
}
else{
// cout << "No" << endl;
if(str[i] == ']'){
while(!st.empty() && st.top() != '['){
int b = cost.top();
cost.pop();
int a = cost.top();
cost.pop();
char op = st.top();
st.pop();
cost.push(cal(a,b,val[op]));
}
st.pop();
kid();
}
else{
st.push(str[i]);
}
}
}
while(!st.empty()){
int a = cost.top();
cost.pop();
int b = cost.top();
cost.pop();
char op = st.top();
st.pop();
cost.push(cal(a,b,val[op]));
}
cout << cost.top();
}