竞赛讨论区 > stringstream 实现逗号分隔
头像
彼岸蒹葭
发布于 2020-03-22 18:44
+ 关注

stringstream 实现逗号分隔

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <sstream>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main(){
    string str;
    
    while (getline(cin, str)){
        stringstream ss;
        ss << str;
        string s; // 接受字符串
        vector<string> sortstring;
        while (getline(ss,s,',')){ // 这里实现了用逗号分隔
            sortstring.push_back(s);
        }
        sort(sortstring.begin(), sortstring.end());
        for (int i = 0; i < sortstring.size()-1; ++i)
            cout << sortstring[i] << ",";
        cout << sortstring[sortstring.size()-1] << endl;
    }
    return 0;
}


全部评论

(0) 回帖
加载中...
话题 回帖

等你来战

查看全部

热门推荐