File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -253,6 +253,47 @@ func main(){
253253```
254254
255255
256+ ### C:
257+ ``` C
258+ #include < stdio.h>
259+ #include < string.h>
260+
261+ void reverse (char * s, int left, int right)
262+ {
263+ while(left <= right)
264+ {
265+ char c = s[ left] ;
266+ s[ left] = s[ right] ;
267+ s[ right] = c;
268+ left++;
269+ right--;
270+ }
271+ }
272+
273+ void rightRotate(char * s, int k)
274+ {
275+ int len = strlen(s);
276+ // 先局部反转再整体反转
277+ reverse(s, 0, len - k - 1); // 反转前部分
278+ reverse(s, len - k, len - 1); // 反转后部分:后k位
279+ reverse(s, 0, len - 1); // 整体反转
280+ }
281+
282+ int main()
283+ {
284+
285+ int k;
286+ scanf("%d", &k);
287+ char s[10000];
288+ scanf("%s", s);
289+
290+ rightRotate(s, k);
291+ printf("%s\n", s);
292+
293+ return 0;
294+ }
295+ ```
296+
256297### JavaScript:
257298
258299
You can’t perform that action at this time.
0 commit comments