题解 | #大整数排序#

大整数排序

https://www.nowcoder.com/practice/b744af632ac4499aa485d7bb048bb0aa

加油,就是字符串排序。不过这里我们需要稍微改进一下默认的排序。

#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
using namespace std;

int main() {
    int n;
    while (cin >> n) {
        vector<string> f;
        for (int i = 0; i < n; i++) {
            string s; cin >> s;
            f.emplace_back(s);
        }
        sort(f.begin(), f.end(), [](string a, string b) {
            if (a.length() != b.length()) return a.length() < b.length();
            return a < b;
        });
        for (int i = 0; i < n; i++) cout << f[i] << endl;
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-09 12:10
直接上图
牛客13578115...:改得一般,不值80
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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