题目链接: 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 ;
}


-->

最新文章

  1. Raab判别法确定级数是否收敛
  2. Android 广播(内部类)
  3. 瞎折腾之 VS2013 Cordova项目的创建与配置
  4. 如果在安装32位oracle 客户端组件时的情况下以64位模式运行,将出现问题
  5. Finding the Longest Palindromic Substring in Linear Time
  6. jquery 直接调用 wcf,面向服务的SOA架构 ( 第三天)
  7. UITextField关闭自动联想功能
  8. 如何设置使chrome新标签页中打开链接自动跳转到新标签页?
  9. python基础-----列表操作
  10. 蜕变成蝶~Linux设备驱动之中断与定时器
  11. eclipse显示xml提示
  12. Bootstrap CustomBox 弹层
  13. 剑指offer二十三之二叉搜索树的后序遍历序列
  14. UltraEdit程序设置添加到右键菜单
  15. Android系统示例分析之AccelerometerPlay
  16. java对象中含有Integer类型字段转json字符串问题
  17. 13-爬取百度贴吧中的图片(python+xpath)
  18. import module与from module import * 两种模块导入有何区别
  19. 2017.11.21 查询某个字段为null的记录
  20. Codeforces Round #425 (Div. 2) D 树链剖分 + 树状数组维护区间

热门文章

  1. mysql的约束
  2. android:修改PagerTabStrip中的背景颜色,标题字体的样式、颜色和图标以及指示条的颜色
  3. 为什么KVM计算机点无故重启?
  4. C经典实例
  5. Linux下编译、安装并启动apache
  6. TCP/IP协议详解之广播和多播
  7. .net Reactor之限指定设备使用
  8. 抛java.lang.NoClassDefFoundError: org.joda.time.ReadablePeriod错误
  9. eclipse中的实用快捷键
  10. python:一个轻松的递归逻辑