<?php
$input = '5.1.2.3.4.2=' ;
$regexp = '/((\\/|\\*|\\+|\\-)(\\/|\\*|\\+))|(^(\\/|\\*|\\+))/' ;
echo "Выражение введено с ошибкой" ;
}
$regexp = '/(?<=\\d)(\\+|\\*|\\/|\\-)(?=(\\-)?\\d(\\.)?)/' ;
$numbersAndSteps [ 0 ] = preg_split ( $regexp , $input , 0 , PREG_SPLIT_NO_EMPTY
) ; foreach ( $numbeAndSteps [ 0 ] as $number ) {
}
$regexp = '/((?<=\\+|\\*|\\/|\\-)\\-?\\d+\\.?\\d*)|(^\\-\\d+\\.?\\d*)/' ;
$numbersAndSteps [ 1 ] = preg_split ( $regexp , $input , 0 , PREG_SPLIT_NO_EMPTY
) ;
$amountOfNumbers = count ( $numbersAndSteps [ 0 ] ) ;
$sum = $numbersAndSteps [ 0 ] [ 0 ] ;
for ( $i = 0 ; $i < $amountOfNumbers ; $i ++ ) {
$followingNumber = $numbersAndSteps [ 0 ] [ $i + 1 ] ;
if ( $numbersAndSteps [ 1 ] [ $i ] == '+' ) {
$sum = $sum + $followingNumber ;
} elseif ( $numbersAndSteps [ 1 ] [ $i ] == '-' ) {
$sum = $sum - $followingNumber ;
} elseif ( $numbersAndSteps [ 1 ] [ $i ] == '*' ) {
$sum = $sum * $followingNumber ;
} elseif ( $numbersAndSteps [ 1 ] [ $i ] == '/' ) {
$sum = $sum / $followingNumber ;
}
}
echo "Ответ: {$sum} " ;
PD9waHAKIAplcnJvcl9yZXBvcnRpbmcoLTEpOwptYl9pbnRlcm5hbF9lbmNvZGluZygndXRmLTgnKTsKCiRpbnB1dCA9ICc1LjEuMi4zLjQuMj0nOwoKJHJlZ2V4cCA9ICcvKChcXC98XFwqfFxcK3xcXC0pKFxcL3xcXCp8XFwrKSl8KF4oXFwvfFxcKnxcXCspKS8nOwppZiAocHJlZ19tYXRjaCgkcmVnZXhwLCAkaW5wdXQpKSB7CgllY2hvICLQktGL0YDQsNC20LXQvdC40LUg0LLQstC10LTQtdC90L4g0Y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