| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
一个H2O【146K 0ms】#include <stdio.h>
#include <cstring>
using namespace std;
int main() {
while(1){
char str[55] = {'\0'};
scanf("%s", str);
int len = strlen(str);
//printf("%d\n", len);
if(str[0] == '#') break;
int pos = len - 1;
while(pos >= 1 && str[pos] <= str[pos-1]){
pos --;
}
//printf("%d\n", pos);
if(pos == 0){
printf("No Successor\n");
continue;
}
char temp = str[pos - 1];
int da;
for(int i = len-1; ; i--){
if(str[i] > temp){
da = i;
break;
}
}
str[pos - 1] = str[da];
str[da] = temp;
for(int i = 0; i < pos; i++){
printf("%c", str[i]);
}
for(int i = len-1; i >= pos; i--){
printf("%c", str[i]);
}
printf("\n");
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator