C语言实现左旋字符串

来源:转载

--------------------------------------------------------------------------------------      例如:字符串:AABCD     左旋一个字符为:ABCDA
                              左旋两个字符为:BCDAA
------------------------------------------------------------------------------------------
 
C语言代码:
 

# include <stdio.h># include <stdlib.h># include <string.h># define MAX 20void Contra_solem(char *str, int move){ char *pstart = NULL; char *pend = NULL; char *src = NULL; int i = 0; pstart = str; pend = (str + strlen(str)); src = str; for (i = 0; i < move; i++) { *pend++ = *pstart++; } while (pstart <= pend) { *src = *pstart; pstart++; src++; }}int main(){ char str[MAX] = "abcdefgh"; int move = 0; printf("源字符串为:%s/n",str); printf("输入想要左旋字符的个数:"); scanf("%d", &move); while (move > strlen(str)) { printf("@@@输入太大,请重新输入!@@@/n"); scanf("%d",&move); } Contra_solem(str,move); printf("左旋%d个字符后的字符串为:%s/n",move,str); system("pause"); return 0;}

 


 



分享给朋友:
您可能感兴趣的文章:
随机阅读: