stable_sort和lambda表达式实现稳定排序
字符串排序
http://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
getline(cin, s);
string s2;
for (char c : s) {
if (isalpha(c)) s2 += c;
}
stable_sort(s2.begin(), s2.end(),
[] (char c1, char c2) {return tolower(c1) < tolower(c2);});
size_t idx = 0;
for (char c : s) {
if (isalpha(c)) {
cout << s2[idx++];
} else {
cout << c;
}
}
cout << endl;
}