百度字符移位

xiaoxiao2021-02-28  126

//把一个字符串的大写字母放到字符串的后面,各个字符的相对位置不变,且不能申请额外的空间。 #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; }
转载请注明原文地址: https://www.6miu.com/read-39711.html

最新回复(0)