@MaksimSienchien/

LimitedTrimAfkgaming-1

PHP (Legacy)

No description

fork
loading
main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
error_reporting(-1);
mb_internal_encoding('utf-8');

$input='5-7+80*2+5*4=';
$inputLenght=mb_strlen($input);
$number=0;
$result=0;
$op='';
for ($i=0; $i<$inputLenght; $i++)
	{			
		$char = mb_substr($input, $i, 1);
		if (is_numeric($char))
		{
			$charArray[]=$char;
		}
		elseif ($char=='+' || $char=='-' || $char=='*'|| $char=='=')
		{
			$number=implode($charArray);
			$number=intval($number);
			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 ($char=='=')
			{
				echo "Ответ: $input$result";
			}
			$op=$char;
			$charArray=[];	
		}
		else
		{
			echo "Неверный символ: [$char]\n";
			exit();
		}
	}
?>
PHP 7.0.8 (Legacy: use the following for new features: Command-line PHP: https://repl.it/languages/php_cli PHP Web Server: https://repl.it/languages/php7