string比较大小就是按照字典序比较的,所以可以直接使用sort

字串的连接最长路径查找

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

#include <bits/stdc++.h>

using namespace std;

int main()
{

    int n;
/*
    bool (*strcompare)(const string &a, const string &b) = [](const string &a, const string &b)->bool{
        int i(0);
        for(;i<a.length()&&i<b.length();i++){
            if(a[i]==b[i])
                continue;
            if(a[i]<b[i])
                return true;
            else
                return false;
        }
        if(i==a.length())
            return true;
        return false;
    };
*/
    while(cin>>n){
        vector<string> data;
        while(n--){
            string instr;cin>>instr;
            data.push_back(instr);
        }
        //sort(data.begin(),data.end(),strcompare);
        sort(data.begin(),data.end());
        for(auto str:data){
            cout<<str<<endl;
        }
    }

    return 0;
}

我蠢比了,还自己写了一个比较的函数

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-10 11:45
你不要过来啊啊啊啊啊啊啊
码农索隆:对面:“今天你不面也得面”
点赞 评论 收藏
分享
舂锋:不能投什么岗都用一份简历,一般都是要看企业的岗位需求来写职业技能或者是项目经历,跟岗位相关的就写多一点。
点赞 评论 收藏
分享
下个早班:秒挂就是不缺人
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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