可行

#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
    string a;
    vector<string> result(100);
    int q=0;
    while(cin>>a)
    {
        result[q] = a;
        q++;
        if(cin.get()=='\n')
        {
            //int num= result.size();
            for(int i= 0;i<q-1;i++)
                for(int j=0; j<q-i-1; j++)
                    if(result[j] > result[j+1])
                    {
                        string temp = result[j];
                        result[j] = result[j+1];
                        result[j+1] = temp;
                    }
            for(int i = 0;i< q;i++)
            cout << result[i] <<' ';
            cout << endl;
            q=0;
            result.empty();
        }
    }
    return 0;
}
全部评论
#include<iostream> #include<sstream> #include<vector> #include<string> #include<algorithm> using namespace std; int main(void) {     string str;     while(getline(cin, str)){         vector<string> p;         string tmp;                  stringstream ss;         ss << str;         while(ss >> tmp)             p.push_back(tmp);                  sort(p.begin(),p.end());         for(int i=0; i<p.size()-1; i++)             cout << p[i] << ' ';         cout << p[p.size()-1] << endl;     }          return 0; }
1 回复 分享
发布于 2019-12-16 16:03

相关推荐

不愿透露姓名的神秘牛友
07-04 18:02
好不容易拿到了字节Offer,鼠鼠做后端的,但家里人觉得可能被裁员不稳定,让鼠鼠去投国企,现在好纠结到底该咋选
文档传偷助手:该投就投吧,不过建议别放弃offer 拿到手里的才是最好的
投递字节跳动等公司8个岗位
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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