8.字符串排序(1)
对输入的字符串进行排序后输出
输入描述:输入有两行,第一行n 第二行是n个字符串,字符串之间用空格隔开
输出描述:输出一行排序后的字符串,空格隔开,无结尾空格
示例
输入例子:
5
c d a bb e
输出例子:
a bb c d e
/*int main()
{
int n;
cin >> n;
string a[100];
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, n + a);
for (int i = 0; i < n - 1; i++)
cout << a[i] << ' ';
cout << a[n - 1];
}
*/
9.字符串排序(2)
对输入的字符串进行排序后输出
输入描述:
多个测试用例,每个测试用例一行。 每行通过空格隔开,有n个字符,n<100
输出描述:
对于每组测试用例,输出一行排序过的字符串,每个字符串通过空格隔开
示例
输入例子:
a c bb f dddd nowcoder
输出例子:
a bb c dddd f nowcoder
/*int main() {
string n;
vector<string> res;
while (cin >> n) {
res.push_back(n);
if (cin.get() == '\n') {
sort(res.begin(), res.end());
for (int i = 0; i < res.size(); i++) {
cout << res[i] << " ";
}
cout << endl;
res.clear();
}
}
return 0;
}*/
10.字符串排序(3)
对输入的字符串进行排序后输出
输入描述:
多个测试用例,每个测试用例一行。 每行通过,隔开,有n个字符,n<100
输出描述:
对于每组用例输出一行排序后的字符串,用','隔开,无结尾空格
示例1
输入例子:
a,c,bb f,dddd nowcoder
输出例子:
a,bb,c dddd,f nowcoder
int main()
{
string str;
while (getline(cin, str)) {
string temp;
vector<string>res;
istringstream ss(str);
while (getline(ss, temp, ',')) {
res.push_back(temp);
}
sort(res.begin(), res.end());
for (int i = 0; i < res.size(); i++) {
if (i == res.size() - 1)
cout << res[i] << endl;
else
cout << res[i] << ',';
}
}
}