会有一个用户给定的输入,我必须把它按字母顺序排列,大写字母在前,小写字母在后。C++例如,输入是GoodMorning,输出是GMdginnooor。
很简单,用下面的方法就可以了。
#include <iostream>
#include <algorithm>
int main(void)
{
std::string text;
std::cout << "Input a string: ";
getline(std::cin, text);
std::sort(text.begin(), text.end());
std::cout << text;
return 0;
}
输出示例
Input a string: GoodMorning
GMdginnooor
希望对你有所帮助!