Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
77751 sh25_wangtaojie 简单算术表达式求值 C++ 通过 0 MS 248 KB 985 2025-12-26 14:45:04

Tests(1/1):


#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; }


测评信息: