mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
添加0053.替换数字.md PHP版本
This commit is contained in:
@ -369,9 +369,43 @@ main();
|
|||||||
|
|
||||||
### Scala:
|
### Scala:
|
||||||
|
|
||||||
|
|
||||||
### PHP:
|
### PHP:
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
// 标准输入
|
||||||
|
$s = trim(fgets(STDIN));
|
||||||
|
$oldLen = strlen($s);
|
||||||
|
$count = 0;
|
||||||
|
for ($i = 0; $i < $oldLen; $i++) {
|
||||||
|
if (is_numeric($s[$i])) {
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 扩充字符串
|
||||||
|
$s = str_pad($s, $oldLen + $count * 5);
|
||||||
|
$newLen = strlen($s);
|
||||||
|
while($oldLen >= 0) {
|
||||||
|
if (is_numeric($s[$oldLen])) {
|
||||||
|
$s[$newLen--] = 'r';
|
||||||
|
$s[$newLen--] = 'e';
|
||||||
|
$s[$newLen--] = 'b';
|
||||||
|
$s[$newLen--] = 'm';
|
||||||
|
$s[$newLen--] = 'u';
|
||||||
|
$s[$newLen--] = 'n';
|
||||||
|
} else {
|
||||||
|
$s[$newLen--] = $s[$oldLen];
|
||||||
|
}
|
||||||
|
$oldLen--;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $s;
|
||||||
|
?>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Rust:
|
### Rust:
|
||||||
|
|
||||||
@ -381,4 +415,3 @@ main();
|
|||||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user