1、HJ14 字符串排序(简单)
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string str;
vector<string> vec;
int num;
cin >> num;
while (cin >> str) {
vec.push_back(str);
}
sort(vec.begin(), vec.end(), [](string s1, string s2){return s1.compare(s2) <= 0;});
for (int i = 0; i < vec.size(); ++i) {
cout << vec[i] << endl;
}
}
// 64 位输出请用 printf("%lld")
2、HJ26 字符串排序(中等)
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str;
cin >> str;
for (int i = 0; i < str.size() - 1; i++)
{
int temp = 0;
for (int j = 0; j<str.size() - i; j++)
{
if (!isalpha(str[temp]))
{
temp = j;
continue;
}
if (isalpha(str[j]))
{
if (tolower(str[temp])>tolower(str[j]))
swap(str[temp], str[j]);
temp = j;
}
}
}
cout << str << endl;
return 0;
}