题目:小Q最近遇到了一个难题:把一个字符串的大写字母放到字符串的后面,各个字符的相对位置不变,且不能申请额外的空间。
你能帮帮小Q吗?
输入描述:
输入数据有多组,每组包含一个字符串s,且保证:1<=s.length<=1000.
输出描述:
对于每组数据,输出移位后的字符串。
输入例子:
AkleBiCeilD
输出例子:
kleieilABCD
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
const int maxn = 1010;
void digitalMvoe(string &str) {
int len = str.length();
for(int i = len-1; i >= 0; i--) {
if(isupper(str[i]) && i+1 < len) {
if(isupper(str[i+1])) {
continue;
} else if(islower(str[i+1])) {
int now = i;
int next = now+1;
while(next <= len-1 && islower(str[next])) {
swap(str[now], str[next]);
now++;
next++;
}
}
}
}
cout << str << endl;
}
int main()
{
string str;
while(cin>>str) {
digitalMvoe(str);
}
return 0;
}