题解 | #后缀子串排序#

后缀子串排序

http://www.nowcoder.com/practice/f89f96ea3145418b8e6c3eb75773f65a

善用STL

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

int main()
{
    string str;
    cin >> str;
    vector<string> toSort;
    for (int i = 0; i < str.size(); ++i) //分割子串
        toSort.push_back(str.substr(i));
    sort(toSort.begin(), toSort.end()); //默认字典序排序
    for (int i = 0; i < toSort.size(); ++i)
        cout << toSort[i] << endl;
    return 0;
}
全部评论

相关推荐

02-12 00:59
已编辑
哈尔滨工业大学 产品经理
华为 软件开发岗 20.6*16薪 本科
点赞 评论 收藏
分享
02-01 19:48
门头沟学院 Java
神哥了不得:(非引流)直接暑期吧,没时间日常了,老鱼简历把水印去了,或者换个模板,简历字体大小都不太行,建议换2个高质量的项目,面试应该还会再多一些
点赞 评论 收藏
分享
评论
6
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务