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;
}
全部评论

相关推荐

黑皮白袜臭脚体育生:简历统一按使用了什么技术实现了什么功能解决了什么问题或提升了什么性能指标来写会更好
点赞 评论 收藏
分享
评论
5
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务