题解 | #字符串排序#

字符串排序

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

#include <cstdio>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;

bool com(string a,string b){
    return a.size()<b.size();
}

int main() {
    int n;
    string str;
    vector<string> vec;
    while (cin >> n) {
        vec.clear();
        n=n+1;
        while (n--) {
            getline(cin, str);
            if (str == "stop") break;
            vec.push_back(str);
        }
        int u = vec.size();
        sort(vec.begin(), vec.end(),com);
        cout<<vec[0];
        for (int i = 1; i <u; i++) cout << vec[i] << endl;
    }

}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

谁知道呢_:要掉小珍珠了,库库学三年,这个结果
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务