#include #include #include char str[60000]; int str_len = 0; /// /// グローバル変数strの中身を入力された文字列で上書きする /// void ReadString() { char c = getchar(); str_len = 0; while (c != '\n') { str[str_len] = c; c = getchar(); str_len++; } } int main() { ReadString(); int nowSym = -1; int ans = 0; int nowNum = 0; for (int i = 0;i < str_len;i++) { if (str[i] == '*') { if (nowSym == -1) { ans = nowNum; } else { if (nowSym == 0) ans += nowNum; if (nowSym == 1) ans *= nowNum; } nowSym = 0; nowNum = 0; continue; } if (str[i] == '+') { if (nowSym == -1) { ans = nowNum; } else { if (nowSym == 0) ans += nowNum; if (nowSym == 1) ans *= nowNum; } nowSym = 1; nowNum = 0; continue; } nowNum = nowNum * 10 + (str[i] - '0'); } if (nowSym == 0) { ans += nowNum; } else { ans *= nowNum; } printf("%d\n",ans); }