题解 | #字符串排序#

字符串排序

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

简单题,sort排序一把梭

字典序直接用下边这个就好了

bool cmp(string a, string b) {
    return a < b;
}
#include <bits/stdc++.h>
using namespace std;

bool cmp(string a, string b) {
    return a < b;
}

void sortasDic(vector<string> s) {
    sort(s.begin(), s.end(), cmp);
    for(int i = 0; i < s.size(); i++) {
        cout<< s[i] <<endl;
    }
}

int main()
{
    vector<string> str;
    string s;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> s;
        str.push_back(s);
    }
    sortasDic(str);
    return 0;
}
全部评论

相关推荐

今天 11:16
湖南大学 Web前端
点赞 评论 收藏
分享
一tiao酸菜鱼:秋招还没正式开始呢,就准备有结果了。。。。?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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