左旋字符串

来源:互联网 发布:软件界面设计要求 编辑:程序博客网 时间:2024/06/08 09:20
// 翻转字母和数字串的位置 #include <iostream>using namespace std;void rotationLeft(char *,int,int);int main(){    char str[30] = "adfaefwefdasf34564545"; //12  20    cout<<str<<endl;    int i;    for(i=0;;i++) //找到数字起始位置     {      if(str[i]<='9'&&str[i]>='0')        break;                  }    int j;    for(j=i;str[j]!='\0';j++)      ;        rotationLeft(str,0,i-1);    rotationLeft(str,i,j-1);    rotationLeft(str,0,j-1);    cout<<str;    cin.get();}void rotationLeft(char *str,int start,int end){   for(int i=start;i<=(start+end)/2;i++)   {     char temp;     temp = str[i];str[i] = str[end-(i-start)];str[end-(i-start)] = temp;           }  }