题解 | #字符串排序#

字符串排序

https://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int a;
    cin >> a;
    vector<string> lines;
    for (int i = 0;i < a;i++) {
        string line;
        getline(cin, line);
        cin >> line;
        lines.push_back(line);
    }

    stable_sort(lines.begin(), lines.end());
    
    for (auto e : lines) {
        cout << e << endl;
    }
}
// 64 位输出请用 printf("%lld")

原来所谓的按照字典序排列就是直接sort,不过是对于字符串的序列。
不过用sort还是用stable_sort就看个人了。

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务