#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int cmp(const char&a,const char& b)//自定义cmp函数,用来确定sort函数的排序原则
{
if(a > b)
return 1;
else
return 0;
}
int main()
{
string str;
cin >> str;
cout << *max_element(str.begin(),str.end()) << endl;
cout << *min_element(str.begin(),str.end()) << endl;
sort(str.begin(),str.end());
cout << str << endl;
sort(str.begin(),str.end(),cmp);
cout << str << endl;
return 0;
}
sort函数、max_element和min_element函数
最新推荐文章于 2024-04-19 21:42:08 发布
本文通过一个C++程序示例介绍了如何使用标准库函数来处理字符串,包括查找最大和最小元素、排序等操作,并自定义了一个比较函数实现特定排序。
2518

被折叠的 条评论
为什么被折叠?



