фух 2 часа делал - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of фух 2 часа делал.php
- <?php
- /**
- * @param string $roman
- * @return int
- */
- function romanToNumber($roman){
- $roman = strtoupper($roman);
- $romans = [
- 'M' => 1000,
- 'CM' => 900,
- 'D' => 500,
- 'CD' => 400,
- 'C' => 100,
- 'XC' => 90,
- 'L' => 50,
- 'XL' => 40,
- 'X' => 10,
- 'IX' => 9,
- 'V' => 5,
- 'IV' => 4,
- 'I' => 1,
- ];
- $result = 0;
- foreach ($romans as $key => $value) {
- while (strpos($roman, $key) === 0) {
- $result += $value;
- $roman = substr($roman, strlen($key));
- }
- }
- return $result;
- }
- //uisng
- echo romanToNumber('mm'); // 2000
- echo romanToNumber('XIV'); // 14