题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
#include <bits/stdc++.h> using namespace std; int main() { string s; while (getline(cin, s)) { string raw_s = s; stable_sort(s.begin(), s.end(), [](char a, char b){ if(!isalpha(a)||!isalpha(b)){ if(!isalpha(a)) return false; if(!isalpha(b)) return true; } return tolower(a)<tolower(b); }); int p = 0; for(int i=0;i<s.size();i++){ if(!isalpha(raw_s[i])) cout<<raw_s[i]; else{ cout<<s[p]; p++; } } } }