/*
* POJ_1146.cpp
*
* Created on: 2013年10月8日
* Author: Administrator
*/ #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring> using namespace std; char s[60];
int l; bool get(){
int i = l - 1;
int j; while(i > 0 && s[i-1] >= s[i]){
i--;
}
if(!i){
return false;
} int mp = i;
for(j = i + 1 ; j < l ; ++j){
if(s[i-1] >= s[j]){
continue;
} if(s[j] < s[mp]){
mp = j;
}
} swap(s[mp],s[i-1]);
sort(s+i,s+l);
return 1;
} int main(){
while(scanf("%s",&s)!=EOF,s[0] !='#'){
l = strlen(s);
if(get()){
printf("%s\n",s);
}else{
printf("No Successor\n");
}
}
}

(组合数学3.1.1.1)POJ 1146 ID Codes(字典序法)的更多相关文章

  1. poj 1146 ID Codes (字符串处理 生成排列组合 生成当前串的下一个字典序排列 【*模板】 )

    ID Codes Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6229   Accepted: 3737 Descript ...

  2. POJ 1146 ID Codes 用字典序思想生成下一个排列组合

    ID Codes Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7644   Accepted: 4509 Descript ...

  3. POJ 1146 ID Codes (UVA146)

    // 求下一个排列// 如果已经是最后一个排列// 就输出 No Successor// stl 或 自己写个 生成排列 我测试了下 两个速率是一样的.只是代码长度不同 /* #include < ...

  4. ACM POJ 1146 ID Codes

    题目大意:输入一个字符串.输出它的下一个字典序排列. 字典序算法思想: 1.从右向左寻找字符串找出第一个a[i]<a[i+1]的位置i; 2.从右向左找出第一个大于a[i]的元素a[j]; 3. ...

  5. 【水一发next_permutation】poj 1146——ID Codesm

    来源:点击打开链接 求字典序下一位,没有直接输出没有.全排列函数秒水过. #include <iostream> #include <algorithm> #include & ...

  6. 1146 ID Codes

    题目链接: http://poj.org/problem?id=1146 题意: 给定一个字符串(长度不超过50), 求这个字符串的下一个字典序的字符串, 如果已经是最大字典序, 那么输出 " ...

  7. POJ 1146:ID Codes

    ID Codes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6281 Accepted: 3769 Description ...

  8. uva146 ID codes

    Description It is 2084 and the year of Big Brother has finally arrived, albeit a century late. In or ...

  9. Brute Force & STL --- UVA 146 ID Codes

     ID Codes  Problem's Link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&a ...

随机推荐

  1. C#中如何正确的操作字符串?

    字符串应该是所有编程语言中使用最频繁的一种基础数据类型.如果使用不慎,我们就会为一次字符串的操作所带来的额外性能开销而付出代价.本条建议将从两个方面来探讨如何规避这类性能开销: 1. 确保尽量少的装箱 ...

  2. Ubuntu系列Crontab日记记录

    修改rsyslog文件,将/etc/rsyslog.d/50-default.conf 文件中的#cron.*前的#删掉 重启rsyslog服务service rsyslog restart 重启cr ...

  3. log4j文件

    log4j文件是一种开源日志记录工具,其作用是记录程序运异常行过程中的重要的操作信息和记录可能出现的异常情况便于调试. 根据日志记录的信息内容可分为3类: Sql日志:记录系统执行的SQL语句 异常日 ...

  4. Angular简单应用剖析

    这一篇我们将一起感受学习一个小型的.活生生的应用,而不是继续深入分析哪些单个的特性.我们将会一起感受一下,前面所讨论过的所有片段如何才能真正的组合在一起,形成一个真实的.可以运行的应用. GutHub ...

  5. sec:authorize 标签 通过不通过权限例子

    1. 方式一     <sec:authorize ifAnyGranted="ROLE_A">     <a href="a.jsp"> ...

  6. php session 自定义的设置测试

    <?php // ini_set('session.save_handler', 'user'); // 注意 set_session_save_handler() 一定要在 session_s ...

  7. PHP导出excel信息表格

    //导出表格public function get_exel($fileName,$headArr,$list){//导入PHPExcel类库,因为PHPExcel没有用命名空间,只能import导入 ...

  8. MYSQL 错误 :Out of resources when opening file './datagather/mx_domain#P#p178.MYD' (Errcode: 24) 解决办法

    出现Out of resources when opening file './xxx.MYD' (Errcode: 24)错误是因为打开的文件数超过了my.cnf的--open-files-limi ...

  9. 复制档案或目录 linux cp命令详解

    cp (复制档案或目录) [root@linux ~]# cp [-adfilprsu] 来源档(source) 目的檔(destination)[root@linux ~]# cp [options ...

  10. CSS and JavaScript Bundling and Minification in ASP.NET 4.5

    ASP.NET 4.5 includes a new feature to minify and bundle CSS and JavaScript within your web applicati ...