fork download
  1. <?php
  2.  
  3.  
  4. $input = '243+6743-78*2=';
  5. $inputLength = mb_strlen($input);
  6.  
  7. $number = 0;
  8. $result = 0;
  9. $op = '';
  10.  
  11. for ($i = 0; $i < $inputLength; $i++){
  12.  
  13. $char = mb_substr($input, $i, 1);
  14. if ($char == '+' || $char == '-' || $char == '=' || $char == '*') {
  15. if ($op == '') {
  16. $result = $number;
  17. } elseif ($char == '=') {
  18. echo $result;
  19. exit();
  20. }
  21. $op = $char;
  22. $number = 0;
  23. } elseif (is_numeric($char)) {
  24. $char = intval($char);
  25. $number = $number*10 + $char;
  26. } else {
  27. echo "Неверный символ: '$char'\n";
  28. }
  29. }
  30.  
  31. ?>
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
243