/*
有一个由大小写组成的字符串,现在需要对他进行修改,将其中的所有小写字母排在大写字母的前面
(大写或小写字母之间不要求保持原来次序),如有可能尽量选择时间和空间效率高的算法。
c语言函数原型void proc(char *str),也可以采用你自己熟悉的语言。
//*/
#include <iostream>
#include <iomanip>
#include <limits>
using namespace std;
void swap_char(char &a, char &b){
char tmp;
tmp = a;
a = b;
b = tmp;
}
int main()
{
char str[] = "bASdDasMKjjkhfJOASDLfsdlfLASDFJKLJ";
int sz = sizeof(str);
cout << str <<endl << sz << endl;
int ps, pe;
ps = 0;
pe = sz-2;
while(ps < pe){
while(str[ps] >= 'a'&& str[ps] <= 'z'){
if(ps >= pe) {break;}
++ps;
}
while(str[pe] >= 'A' && str[pe] <= 'Z'){
if(ps >= pe) {break;}
--pe;
}
swap_char(str[ps], str[pe]);
}
cout << str <<endl;
}