// // main.cpp // Q461 // // Created by AkihiroKOBAYASHI on 7/11/15. // Copyright (c) 2015 Akhr5884. All rights reserved. // #include #include #include #include #include char temp[20]; int head = 0; void pushStack(char moji) { temp[head] = moji; head++; } int popStack() { std::string stack; stack = temp; memset( temp , NULL , sizeof(temp) ); head = 0; std::cout << stoi(stack) << '\n'; return std::stoi(stack); } int main(int argc, const char * argv[]) { char moji[40]; char fugou = '+'; std::string formula; int f_length, i, j, value, maxvalue; maxvalue = value = 0; std::cin >> formula; f_length = (int)formula.length(); formula = formula + formula; sprintf(moji, "%s", formula.c_str()); for(i = 0; i < f_length; i++) { value = 0; if(std::isdigit(static_cast(moji[i])) && std::isdigit(static_cast(moji[i+f_length-1]))) { for(j = i; j < i + f_length; j++) { if(moji[j] == '+' || moji[j] == '-'){ if(fugou == '+') { value += popStack(); } else if(fugou == '-') { value -= popStack(); } fugou = moji[j]; } else { pushStack(moji[j]); } } if(fugou == '+') { value += popStack(); } else if(fugou == '-') { value -= popStack(); } if(value > maxvalue) { maxvalue = value; } } } std::cout << maxvalue << '\n'; return 0; }