更新时间:2023-02-23 09:12:13
有< algorithm> 中的标题库中的w / cpp / algorithm / sort>排序算法。它排在现场,所以如果你做以下,你的原始单词将排序。
There is a sorting algorithm in the standard library, in the header <algorithm>
. It sorts inplace, so if you do the following, your original word will become sorted.
std::sort(word.begin(), word.end());
如果您不想丢失原件,请先复制。
If you don't want to lose the original, make a copy first.
std::string sortedWord = word;
std::sort(sortedWord.begin(), sortedWord.end());