题解 | #字符串排序#

字符串排序

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

使用vector容器存储输入的数据,很多人使用push,这点可以优化,使用emplace相关的操作,
emplace相关操作比push效果更好,不明白的看相关的push和emplace的区别

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

int main(){
    int n;
    cin>>n;
    vector<string> res;
    string s;
    while(n--){
        cin>>s;
        res.emplace_back(s);
    }
    sort(res.begin(),res.end());
    for(string str:res)
        cout<<str<<endl;
    return 0;
}
#社畜简单的快乐#
全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 12:10
点赞 评论 收藏
分享
06-25 09:33
厦门大学 Java
程序员饺子:现在日常估计没啥hc了,等到八月多估计就慢慢有了。双九✌🏻不用焦虑的
投递快手等公司7个岗位
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 14:08
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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