Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- bool isAlp(char s){
- return 'A' <= s and s <= 'Z';
- }
- int Imp(char a){
- if(a == '1') return 1;
- else if(a == '2') return 2;
- else if(a == '3') return 3;
- else if(a == '[') return 0;
- }
- int Per(int x, char a){
- if(a == '1') return (int)(x * 0.04);
- else if(a == '2') return (int)(x * 0.08);
- else if(a == '3') return (int)(x * 0.16);
- }
- void Debug(stack <int> num, stack <char> opr){
- printf("num : ");
- while(!num.empty()) printf("%d ", num.top()), num.pop();
- printf("\n");
- printf("opr : ");
- while(!opr.empty()) printf("%c ", opr.top()), opr.pop();
- printf("\n\n");
- }
- int main(){
- string str;
- cin >> str;
- int len = str.size();
- stack <int> num;
- stack <char> opr;
- for(auto s: str){
- //printf("%c\n", s);
- if(s == '['){
- opr.push(s);
- }
- else if(s == ']'){
- while(opr.top() != '['){
- int a = num.top(); num.pop();
- int b = num.top(); num.pop();
- int x = a + b + Per(a + b, opr.top());
- opr.pop();
- num.push(x);
- }
- opr.pop();
- }
- else if(isAlp(s)){ /// A B C ... X Y Z
- num.push(20);
- }
- else{ /// 1 2 3
- if(opr.empty() or Imp(s) > Imp(opr.top())) opr.push(s);
- else{
- while(!opr.empty() and Imp(s) <= Imp(opr.top())){
- int a = num.top(); num.pop();
- int b = num.top(); num.pop();
- int x = a + b + Per(a + b, opr.top());
- opr.pop();
- num.push(x);
- }
- opr.push(s);
- }
- }
- //Debug(num, opr);
- }
- while(!opr.empty()){
- int a = num.top(); num.pop();
- int b = num.top(); num.pop();
- int x = a + b + Per(a + b, opr.top());
- opr.pop();
- num.push(x);
- }
- printf("%d", num.top());
- return 0;
- }
Advertisement
RAW Paste Data
Copied
Advertisement