1 // ConsoleApplication4.cpp : 定义控制台应用程序的入口点。 2 // 3 4 #include "stdafx.h" 5 #include<iostream> 6 7 using namespace std; 8 9 void fun(char *w, int m) 10 { 11 int i = 0, len = strlen(w); 12 if (m > len) m = len; 13 char temp; 14 while (len - m > 0 ) 15 { 16 temp = w[0]; 17 for (i = 0; i < len-1; i++) 18 { 19 w[i] = w[i + 1]; 20 } 21 w[len - 1] = temp; 22 m++; 23 } 24 } 25 26 int _tmain(int argc, _TCHAR* argv[]) 27 { 28 char w[] = "ABCDEFGHI"; 29 fun(w, 3); 30 cout << w << endl; 31 return 0; 32 }
将w中字符串的倒数m个字符移动到字符串前面,其余一次向右移,例如:ABCDEFGHI,M=3,输出GHIABCDEF