// No.49 算数の宿題 // https://yukicoder.me/problems/no/49 // #include #include #include #include using namespace std; int solve(string &S); pair, vector> separate_string(string &S); int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); string S; cin >> S; int ans = solve(S); cout << ans << endl; } int solve(string &S) { pair, vector> res = separate_string(S); vector numbers = res.first; vector ops = res.second; int ans = numbers[0]; for (auto i = 0; i < numbers.size()-1; ++i) { if (ops[i] == '*') ans += numbers[i+1]; else ans *= numbers[i+1]; } return ans; } pair, vector> separate_string(string &S) { vector numbers; vector ops; string t; for (char c: S) { if (c == '*' || c == '+') { numbers.push_back(stoi(t)); ops.push_back(c); t = ""; } else { t += c; } } numbers.push_back(stoi(t)); return make_pair(numbers, ops); }