<?php
$input = '-243-13.5+9/2=';
$result = 0;
$regexp = '!([0-9\\.]+)!';
$example = preg_split($regexp, $input, 0, PREG_SPLIT_NO_EMPTY
| PREG_SPLIT_DELIM_CAPTURE);
$op = '+';
foreach ($example as $key => $number)
switch($op) {
case '+':
$result += (float)$number;
break;
case '-':
$result -= (float)$number;
break;
case '*':
$result *= (float)$number;
break;
case '/':
$result /= (float)$number;
break;
case '=':
echo "Знак '=' должен быть в конце выражения";
default:
echo "Неподходящий символ $number";
};
}
elseif ($number === "=" and
$key + 1 === count($example)) { echo "Ответ: ", $input, $result; exit();} else
$op = $number;
PD9waHAKCiRpbnB1dCA9ICctMjQzLTEzLjUrOS8yPSc7CiRyZXN1bHQgPSAwOwokcmVnZXhwID0gJyEoWzAtOVxcLl0rKSEnOwoKJGV4YW1wbGUgPSBwcmVnX3NwbGl0KCRyZWdleHAsICRpbnB1dCwgMCwgUFJFR19TUExJVF9OT19FTVBUWXwKIAkgICAgICAgUFJFR19TUExJVF9ERUxJTV9DQVBUVVJFKTsKCiRvcCA9ICcrJzsKCmZvcmVhY2ggKCRleGFtcGxlIGFzICRrZXkgPT4gJG51bWJlcikKCWlmIChwcmVnX21hdGNoKCRyZWdleHAsICRudW1iZXIpKSB7CgkJc3dpdGNoKCRvcCkgewoJCQljYXNlICcrJzoKCQkJCSRyZXN1bHQgKz0gKGZsb2F0KSRudW1iZXI7CgkJCQlicmVhazsKCQkJY2FzZSAnLSc6CgkJCQkkcmVzdWx0IC09IChmbG9hdCkkbnVtYmVyOwoJCQkJYnJlYWs7CgkJCWNhc2UgJyonOgoJCQkJJHJlc3VsdCAqPSAoZmxvYXQpJG51bWJlcjsKCQkJCWJyZWFrOwoJCQljYXNlICcvJzoKCQkJCSRyZXN1bHQgLz0gKGZsb2F0KSRudW1iZXI7CgkJCQlicmVhazsKCQkJY2FzZSAnPSc6CgkJCQllY2hvICLQl9C90LDQuiAnPScg0LTQvtC70LbQtdC9INCx0YvRgtGMINCyINC60L7QvdGG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