Skip to content

Commit f96b0cf

Browse files
committed
添加0053.替换数字.md PHP版本
1 parent 06a26f4 commit f96b0cf

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

problems/kamacoder/0054.替换数字.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,43 @@ main();
369369

370370
### Scala:
371371

372-
373372
### PHP:
374373

374+
```php
375+
<?php
376+
// 标准输入
377+
$s = trim(fgets(STDIN));
378+
$oldLen = strlen($s);
379+
$count = 0;
380+
for ($i = 0; $i < $oldLen; $i++) {
381+
if (is_numeric($s[$i])) {
382+
$count++;
383+
}
384+
}
385+
386+
// 扩充字符串
387+
$s = str_pad($s, $oldLen + $count * 5);
388+
$newLen = strlen($s);
389+
while($oldLen >= 0) {
390+
if (is_numeric($s[$oldLen])) {
391+
$s[$newLen--] = 'r';
392+
$s[$newLen--] = 'e';
393+
$s[$newLen--] = 'b';
394+
$s[$newLen--] = 'm';
395+
$s[$newLen--] = 'u';
396+
$s[$newLen--] = 'n';
397+
} else {
398+
$s[$newLen--] = $s[$oldLen];
399+
}
400+
$oldLen--;
401+
}
402+
403+
echo $s;
404+
?>
405+
```
406+
407+
408+
375409

376410
### Rust:
377411

@@ -381,4 +415,3 @@ main();
381415
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
382416
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
383417
</a>
384-

0 commit comments

Comments
 (0)