按字符串大小进行降序排序
时间: 2023-05-10 11:56:06 浏览: 101
字符串排序
可以使用sort函数和greater比较函数来实现按字符串大小进行降序排序,示例代码如下:
```c++
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
bool greater(string a, string b) {
return a > b;
}
int main() {
vector<string> strs = {"hello", "world", "cpp", "python", "java"};
sort(strs.begin(), strs.end(), greater);
for (auto s : strs) {
cout << s << " ";
}
cout << endl;
return 0;
}
```
输出结果为:
```
world python java hello cpp
```
阅读全文