提交时间:2025-12-26 14:45:04

运行 ID: 77751

#include <iostream> #include <string> #include <sstream> #include <algorithm> using namespace std; int main() { string input; getline(cin, input); input.erase(remove(input.begin(), input.end(), ' '), input.end()); int op_pos = 0; for (char c : input) { if (c == '+' || c == '-' || c == '*' || c == '/' || c == '%') { break; } op_pos++; } string num1_str = input.substr(0, op_pos); string op = input.substr(op_pos, 1); string num2_str = input.substr(op_pos + 1); int num1 = stoi(num1_str); int num2 = stoi(num2_str); int result; if (op == "+") { result = num1 + num2; } else if (op == "-") { result = num1 - num2; } else if (op == "*") { result = num1 * num2; } else if (op == "/") { result = num1 / num2; } else if (op == "%") { result = num1 % num2; } cout << result << endl; return 0; }