/*
* 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(字典序法)
最新推荐文章于 2018-05-01 18:06:00 发布