题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
#include <iostream> using namespace std; #include <bits/stdc++.h> const string alpha = "abcdefghijklmnopqrstuvwxyz"; int main() { string s, temp,res; getline(cin,s); res = s; //搜索字符c和他的大写如果s[i]是字母并填入res中对应的位置 for(int i = 0; i < 26; i++){ char c1 = alpha[i], c2 = toupper(c1); for(int j = 0; j < s.size(); j++){ if(s[j] == c1 || s[j] == c2) { temp += s[j]; } } } int k = 0; for(int i = 0; i < s.size(); i++){ if(!isalpha(s[i])) res[i] = s[i]; else res[i] = temp[k++]; } cout<<res<<endl; } // 64 位输出请用 printf("%lld")