题解 | 字符串排序
字符串排序
https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
#include <iostream>
#include <string>
using namespace std;
string myfun(string& str){
int len=str.size();
string tempStr;
for(int i = 0; i<26; i++){
for(int j = 0; j<len; j++){
if(str[j]-65 == i || str[j]-'a'== i){
tempStr.push_back(str[j]);
}
}
}
for(int i = 0,k=0; i<len&&k<tempStr.size(); i++){
//限制多肯定能提高或保持效率
if(str[i]>=65&&str[i]<=90 || str[i]>=97&&str[i]<='z' ){
str[i]=tempStr[k];
k++;
}
}
return str;
}
int main() {
string a;
getline(cin,a);
cout<<myfun(a);
}
// 64 位输出请用 printf("%lld")


查看12道真题和解析