1146 ID Codes
2024-10-19 06:17:07
题目链接: http://poj.org/problem?id=1146
题意: 给定一个字符串(长度不超过50), 求这个字符串的下一个字典序的字符串, 如果已经是最大字典序, 那么输出 "No successor".
分析: <algorithm>中有一个现成的next_permutation(begin, end), 对输入的字符串进行排列.
原型如下:
template<class BidirectionalIterator>
bool next_permutation(
BidirectionalIterator _First,
BidirectionalIterator _Last
);
template<class BidirectionalIterator, class BinaryPredicate>
bool next_permutation(
BidirectionalIterator _First,
BidirectionalIterator _Last,
BinaryPredicate _Comp
);
AC代码:
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string line; bool comp(char a, char b){
return a>b;
} int main(){
while(cin>>line){
if(line.at() == '#')
break;
string s(line);
sort(s.begin(),s.end(),comp);
if(line == s){
cout<<"No Successor"<<endl;
continue;
}
next_permutation(line.begin(),line.end());
cout<<line<<endl;
}
return ;
}
-->
最新文章
- Raab判别法确定级数是否收敛
- Android 广播(内部类)
- 瞎折腾之 VS2013 Cordova项目的创建与配置
- 如果在安装32位oracle 客户端组件时的情况下以64位模式运行,将出现问题
- Finding the Longest Palindromic Substring in Linear Time
- jquery 直接调用 wcf,面向服务的SOA架构 ( 第三天)
- UITextField关闭自动联想功能
- 如何设置使chrome新标签页中打开链接自动跳转到新标签页?
- python基础-----列表操作
- 蜕变成蝶~Linux设备驱动之中断与定时器
- eclipse显示xml提示
- Bootstrap CustomBox 弹层
- 剑指offer二十三之二叉搜索树的后序遍历序列
- UltraEdit程序设置添加到右键菜单
- Android系统示例分析之AccelerometerPlay
- java对象中含有Integer类型字段转json字符串问题
- 13-爬取百度贴吧中的图片(python+xpath)
- import module与from module import * 两种模块导入有何区别
- 2017.11.21 查询某个字段为null的记录
- Codeforces Round #425 (Div. 2) D 树链剖分 + 树状数组维护区间