<?php /** * 12.05.2015 (8:21) * Calculator.php * PhpStorm */ $input = '243+6743-78*2*1*1*1*1*1+4-3-3817/9='; $number = 0; $result = 0; $op = ''; echo "Пример: {$input}\n\n"; for ($i = 0; $i < $inputLength; $i++) { } elseif ($char == '*' || $char == '+' || $char == '-' || $char == '=' || $char == '/') { echo "op=[{$op}], result=[{$result}], number=[{$number}], char=[{$char}]\n"; if ($op == '') { $result = $number; } if ($op == '*') { $result *= $number; } if ($op == '+') { $result += $number; } if ($op == '-') { $result -= $number; } if ($op == '/') { $result /= $number; } $number = 0; $op = $char; } } echo "\nОтвет: {$result}\n";
Standard input is empty
Пример: 243+6743-78*2*1*1*1*1*1+4-3-3817/9= op=[], result=[0], number=[243], char=[+] op=[+], result=[243], number=[6743], char=[-] op=[-], result=[6986], number=[78], char=[*] op=[*], result=[6908], number=[2], char=[*] op=[*], result=[13816], number=[1], char=[*] op=[*], result=[13816], number=[1], char=[*] op=[*], result=[13816], number=[1], char=[*] op=[*], result=[13816], number=[1], char=[*] op=[*], result=[13816], number=[1], char=[+] op=[+], result=[13816], number=[4], char=[-] op=[-], result=[13820], number=[3], char=[-] op=[-], result=[13817], number=[3817], char=[/] op=[/], result=[10000], number=[9], char=[=] Ответ: 1111.1111111111