#include <map>
#include <iostream>
using Operator = double(double, double);
double plus(double x, double y) {
return x+y;
}
double minus(double x, double y) {
return x-y;
}
double divide(double x, double y) {
return x/y;
}
double multiply(double x, double y) {
return x*y;
}
int main()
{
std::map<char, Operator&> operators = {
{'+', plus},
{'-', minus},
{'/', divide},
{'*', multiply}
};
double x = 0;
double y = 0;
char op = 0;
double result = 0;
std::cout << "Input number, operation (+, -, /, *) and number, please: ";
std::cin >> x >> op >> y;
const auto operation = operators.find(op);
if (operation != operators.cend())
std::cout << "Result: " << (*operation->second)(x, y) << '\n';
else
std::cout << "Operation " << op << " not found!\n";
return 0;
}
I2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgT3BlcmF0b3IgPSBkb3VibGUoZG91YmxlLCBkb3VibGUpOwoKZG91YmxlIHBsdXMoZG91YmxlIHgsIGRvdWJsZSB5KSB7CiAgICByZXR1cm4geCt5Owp9Cgpkb3VibGUgbWludXMoZG91YmxlIHgsIGRvdWJsZSB5KSB7CiAgICByZXR1cm4geC15Owp9Cgpkb3VibGUgZGl2aWRlKGRvdWJsZSB4LCBkb3VibGUgeSkgewogICAgcmV0dXJuIHgveTsKfQoKZG91YmxlIG11bHRpcGx5KGRvdWJsZSB4LCBkb3VibGUgeSkgewogICAgcmV0dXJuIHgqeTsKfQoKaW50IG1haW4oKQp7CiAgICBzdGQ6Om1hcDxjaGFyLCBPcGVyYXRvciY+IG9wZXJhdG9ycyA9IHsKICAgICAgICB7JysnLCBwbHVzfSwKICAgICAgICB7Jy0nLCBtaW51c30sCiAgICAgICAgeycvJywgZGl2aWRlfSwKICAgICAgICB7JyonLCBtdWx0aXBseX0KICAgIH07CiAgICBkb3VibGUgeCA9IDA7CiAgICBkb3VibGUgeSA9IDA7CiAgICBjaGFyIG9wID0gMDsKICAgIGRvdWJsZSByZXN1bHQgPSAwOwogICAgc3RkOjpjb3V0IDw8ICJJbnB1dCBudW1iZXIsIG9wZXJhdGlvbiAoKyw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