OJ在线编程常见输入输出练习10

/*********************************************************************************
Copyright(C),Your Company
Author:	KimChow
Date: 2021-12-31
Description: OJ在线编程常见输入输出练习

对输入的字符串进行排序后输出

输入描述:
多个测试用例,每个测试用例一行。
每行通过,隔开,有n个字符,n<100

输出描述:
对于每组用例输出一行排序后的字符串,用','隔开,无结尾空格

输入例子1:
a,c,bb
f,dddd
nowcoder

输出例子1:
a,bb,c
dddd,f
nowcoder

Others: 打开以下链接可以查看正确的代码
https://ac.nowcoder.com/acm/contest/5657#question
**********************************************************************************/

#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    string strCin;
    while (cin >> strCin)
    {
        vector<string> vecStrList;
        stringstream ss(strCin);
        string strItem;
        while (getline(ss, strItem, ','))
            vecStrList.push_back(strItem);
        
        sort(vecStrList.begin(), vecStrList.end());
        for (unsigned int i = 0; i < vecStrList.size(); i++)
        {
            cout << vecStrList[i];
            if (i < vecStrList.size() - 1)
                cout << ",";
        }
        cout << endl;
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值