//把一个字符串的大写字母放到字符串的后面,各个字符的相对位置不变,且不能申请额外的空间。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int i,j;
string a;
while(cin>>a)
{
int len=a.size();
j=a.size()-1;
while(j>0)
{
while(j>0&&a[j]<='Z'&&a[j]>='A')--j;
int i=j-1;
while(i>=0&&a[i]<='z'&&a[i]>='a')--i;
if(i<j&&i>=0)
{
char t=a[i];
for(int k=i; k<=j-1; k++)
a[k]=a[k+1];
a[j]=t;
}
j--;
}
cout<<a<<endl;
}
return 0;
}
百度字符移位
最新推荐文章于 2024-07-14 18:15:43 发布