将后面的m个数移到前面
#include<iostream> #include<algorithm> #include<stdio.h> #include<numeric> using namespace std; int bigswap(char* a,int start,int end) { while(start<end) { swap(a[start],a[end]); start++; end--; } return 1; } int helper(char* a,int m) { int len = strlen(a); bigswap(a,0,m); bigswap(a,m+1,len-1); bigswap(a,0,len-1); return 1; } int main() { char a[] = "123456789"; // char* a = "123456789"; 报错,是不是因为常量不可更改? helper(a,3); printf("%s",a); }
berkeleysong
posted on 2014-05-19 11:34 berkeleysong 阅读(204) 评论(0) 编辑 收藏 举报