#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include <string.h> void reserve(char *left,char*right) { while (left < right) { char tmp = *left; *left = *right; *right = tmp; left++; right--; } } int main() { char arr[10] = "AABCD"; int len = strlen(arr)-1; int k = 0; char *pstart = &arr[0]; char *pend = arr+len; scanf("%d", &k); reserve(pstart, pstart + k -1); reserve(pstart + k, pend); reserve(pstart, pend); printf("%s\n", arr); system("pause"); return 0; }
【C语言】【笔试题】【面试题】实现一个函数,可以左旋字符串中的k个字符
原文地址:http://10740329.blog.51cto.com/10730329/1709392