LeetCode刷C++刷得飞起,但是做了实习笔试之后才发现我需要练习ACM模式(我太菜了~)
OJ上机笔试输入输出练习
需要花点心思熟练掌握的只有第十题~
字符串排序(3)
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
string str, temp;
vector<string> vec;
int start, i;
while (cin >> str) {
start = 0;
for (i = 0; i < str.size(); i++)
if (str[i] == ',') {
temp = str.substr(start, i - start);
vec.push_back(temp);
start = i + 1;
}
temp = str.substr(start);
vec.push_back(temp);
sort(vec.begin(), vec.end());
for (i = 0; i < vec.size(); i++)
if (i != vec.size() - 1)
cout << vec[i] << ',';
else
cout << vec[i] << endl;
vec.clear();
}
return 0;
}