1146 ID Codes
题目链接: 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 ;
}
-->
1146 ID Codes的更多相关文章
- poj 1146 ID Codes (字符串处理 生成排列组合 生成当前串的下一个字典序排列 【*模板】 )
ID Codes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6229 Accepted: 3737 Descript ...
- POJ 1146 ID Codes 用字典序思想生成下一个排列组合
ID Codes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7644 Accepted: 4509 Descript ...
- POJ 1146 ID Codes (UVA146)
// 求下一个排列// 如果已经是最后一个排列// 就输出 No Successor// stl 或 自己写个 生成排列 我测试了下 两个速率是一样的.只是代码长度不同 /* #include < ...
- (组合数学3.1.1.1)POJ 1146 ID Codes(字典序法)
/* * POJ_1146.cpp * * Created on: 2013年10月8日 * Author: Administrator */ #include <iostream> #i ...
- ACM POJ 1146 ID Codes
题目大意:输入一个字符串.输出它的下一个字典序排列. 字典序算法思想: 1.从右向左寻找字符串找出第一个a[i]<a[i+1]的位置i; 2.从右向左找出第一个大于a[i]的元素a[j]; 3. ...
- POJ 1146:ID Codes
ID Codes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6281 Accepted: 3769 Description ...
- uva146 ID codes
Description It is 2084 and the year of Big Brother has finally arrived, albeit a century late. In or ...
- Brute Force & STL --- UVA 146 ID Codes
ID Codes Problem's Link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&a ...
- UVA 146 ID Codes(下一个排列)
C - ID Codes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Statu ...
随机推荐
- Java并发-Runnable、Callable、Future、Future Task
Runnable: Runnable的代码非常简单,他是一个接口,且接口中只有一个方法,run(),创建一个类实现他,把一些费时操作写在其中,然后使用某个线程去执行该Runnable实现类即可实现多线 ...
- 2_python之路之多级菜单
python之路之多级菜单 1.使用知识点 (1)列表,字典的使用 (2)if条件判断语句 (3)for/while循环的使用 2.代码详细 #!/usr/bin/env python # _*_ c ...
- 记-cloudstack 更改二级存储
一.问题是由于当初把二级存储挂载到了根分区的文件系统内,并随着慢慢的模板的增加,容量越来越小. 1.先在cloud 网页界面禁用cloudstack区域 2.然后停止cloudstack-manage ...
- 一些通用的触发移动App崩溃的测试场景
一些通用的触发移动App崩溃的测试场景,如下: 1 验证在有不同的屏幕分辨率,操作系统和运营商的多个设备上的App行为. 2 用新发布的操作系统版本验证App的行为. 3 验证在如隧道,电梯等网络质量 ...
- 基于OpenCV读取摄像头进行人脸检测和人脸识别
前段时间使用OpenCV的库函数实现了人脸检测和人脸识别,笔者的实验环境为VS2010+OpenCV2.4.4,opencv的环境配置网上有很多,不再赘述.检测的代码网上很多,记不清楚从哪儿copy的 ...
- nginx 代理http配置实例
#user nginx; worker_processes ; #error_log /var/log/nginx/error.log warn; #pid /var/run/nginx.pid; e ...
- Linux启动流程【转载】
探讨操作系统接管硬件以后发生的事情,也就是操作系统的启动流程. 这个部分比较有意思.因为在BIOS阶段,计算机的行为基本上被写死了,程序员可以做的事情并不多:但是,一旦进入操作系统,程序员几乎可以定制 ...
- DataGrid 扩展
//扩展表格,支持上传附件 function extendDataGrid(){ //扩展表格方法,合并单元格 ,参数为数组 $.extend($.fn.datagrid.methods, { aut ...
- SQL 返回刚插入数据的ID
处理方法在某个字段上加上identity id int identity(1,1), 创建标识的三种方法及比较: SQL Server 2000中,有三个比较类似的功能:他们分别是:SCOPE_IDE ...
- Mysql Windows 7 异常关闭, 2003 - Can't connect to Mysql server on 'localhost' (10061) "Unknown error")
如下: 按Win+R在窗口输入services.msc 启动mysql服务