File tree Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change 23
23
```
24
24
2
25
25
abcdefg
26
- ```
26
+ ```
27
27
28
28
样例输出:
29
29
@@ -336,6 +336,32 @@ var reverseLeftWords = function(s, n) {
336
336
337
337
### PHP:
338
338
339
+ ``` php
340
+ <?php
341
+ // 反转函数
342
+ function reverse(& $s, $start, $end) {
343
+ for ($i = $start, $j = $end; $i < $j; $i++, $j--) {
344
+ $tmp = $s[$i];
345
+ $s[$i] = $s[$j];
346
+ $s[$j] = $tmp;
347
+ }
348
+ }
349
+
350
+ // 标准输入:读取右旋转位数和字符串
351
+ $n = trim(fgets(STDIN));
352
+ $s = trim(fgets(STDIN));
353
+ // 字符串长度
354
+ $len = strlen($s);
355
+ // 先部分反转
356
+ reverse($s, $len - $n, $len - 1);
357
+ reverse($s, 0, $len - $n - 1);
358
+ // 再整体反转
359
+ reverse($s, 0, $len - 1);
360
+
361
+ echo $s;
362
+ ?>
363
+ ```
364
+
339
365
340
366
### Scala:
341
367
@@ -349,3 +375,4 @@ var reverseLeftWords = function(s, n) {
349
375
<a href =" https://programmercarl.com/other/kstar.html " target =" _blank " >
350
376
<img src =" ../pics/网站星球宣传海报.jpg " width =" 1000 " />
351
377
</a >
378
+
You can’t perform that action at this time.
0 commit comments