2021-09-13:整数转罗马数字。
对应起来就行了
https://baike.baidu.com/item/%E7%BD%97%E9%A9%AC%E6%95%B0%E5%AD%97/772296?fr=aladdin
https://cloud.tencent.com/developer/grocery-stall4?invitedUid=6461226
<?php
function intToRoman($num)
{
$n = intval($num);
$result = '';
$lookup = array(
'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
);
foreach ($lookup as $roman => $value)
{
// Look for number of matches
$matches = intval($n / $value);
// Concatenate characters
$result .= str_repeat($roman, $matches);
// Substract that from the number
$n = $n % $value;
}
return $result;
}
以上就是 PHP 版 整数转罗马数字!
不要急,给你看个宝贝!
相似问题