题解 | #求长方体表面积#

字符串排序

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

#include<bits/stdc++.h>
using namespace std;
//按照字典序排序,string直接比大小,可以用multiset直接输出
int main(){
    string strInput="ssr";
    int num = 0;
    cin>>num;
    vector<string> myVec;//不能初始化为{""},导致第一个元素存在且为空
//     while(getline(cin, strInput)){//为什么第一个是空字符串?第一个已经用过了,所以为空了?
//         myVec.push_back(strInput);  
//     }
    for(int i = 0; i<num; ++i){
        cin>>strInput;
        myVec.push_back(strInput);
    }
    for(int i = 0; i<num; ++i){
        for(int j = 0; j<num-i-1; ++j){
            if (myVec[j]>myVec[j+1]) swap(myVec[j], myVec[j+1]);
        }
    }
    for(auto str:myVec){
        cout<<str<<endl;
    }
    return 0;
}
全部评论

相关推荐

06-25 16:25
梧州学院 Java
愿汐_:项目介绍那么长,然而你做了啥就一句话?
点赞 评论 收藏
分享
07-10 14:08
已编辑
江西农业大学 Java
念旧select:做完把项目放到自己硬盘里给他看,看完拷走
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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