将一个字符串,左旋N个字符

来源:互联网 发布:ff14国服数据库 编辑:程序博客网 时间:2024/05/17 01:09
#include "stdio.h"size_t _strlen(char* str){if (str==NULL || *str=='\0') return 0;int count=0;while (*str++){count++;}return count;}void scroll_str(char* str,int step){if (str==NULL || *str=='\0' || step<=0) return;int len=_strlen(str);int real_step=step%(len-1);char c=*str;char* p1=str;char* p2=str+1;for (int i=0;i<real_step;i++){*p1=*p2;p1++;p2++;}*p1=c;}void main(void){char a[]="Hello World!";printf("%s\n",a);scroll_str(a,10);printf("%s\n",a);}

算法待优化
0 0