#include "hotplug.hpp" #include #include #include #include namespace { bool decimal(const std::string &token, long long &result) { std::size_t position = 0; bool negative = false; if (!token.empty() && (token[0] == '+' || token[0] == '-')) { negative = token[0] == '-'; ++position; } if (position == token.size()) { return false; } const auto maximum = static_cast(std::numeric_limits::max()); const auto limit = maximum + (negative ? 1U : 0U); std::uint64_t value = 0; for (; position < token.size(); ++position) { const char digit = token[position]; if (digit < '0' || digit > '9') { return false; } const auto number = static_cast(digit - '0'); if (value > (limit - number) / 10) { return false; } value = value * 10 + number; } if (negative && value == maximum + 1U) { result = std::numeric_limits::min(); } else { result = static_cast(value); if (negative) { result = -result; } } return true; } } int main() { hotplug::Engine engine; std::string line; while (std::getline(std::cin, line)) { std::istringstream input(line); hotplug::Command command; if (!(input >> command.name)) { continue; } std::string token; bool valid = true; while (input >> token) { long long number = 0; if (!decimal(token, number)) { valid = false; } else { command.args.push_back(number); } } if (!valid) { command.name = "?"; command.args.clear(); } const int result = engine.execute(command); std::cout << engine.observe(result); } return 0; }