#include #include #include #include void calc(char *operator, char operant[], int *sum) { if (*operator == '+') *sum += atoi(operant); else *sum -= atoi(operant); } void push(char *x, char operant[], int *top) { operant[*top] = *x; ++*top; operant[*top] = '\0'; } void shift(char S[], int *length) { char tmp = S[*length - 1]; int i; for (i = *length - 1; i > 0; --i) S[i] = S[i - 1]; S[0] = tmp; } int main(void) { char S[11], operant[10], operator; int length, top, sum, max = INT_MIN, i, j; scanf("%s", S); length = strlen(S); for (i = 0; i < length; ++i) { if (S[0] == '+' || S[0] == '-' || S[length - 1] == '+' || S[length - 1] == '-') { shift(S, &length); continue; } operator = '+'; top = 0; sum = 0; for (j = 0; j < length; ++j) { if (S[j] == '+' || S[j] == '-') { calc(&operator, operant, &sum); operator = S[j]; top = 0; } else push(&S[j], operant, &top); } calc(&operator, operant, &sum); if (max < sum) max = sum; shift(S, &length); } printf("%d", max); return 0; }