-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1146.cpp
More file actions
63 lines (55 loc) · 1.23 KB
/
1146.cpp
File metadata and controls
63 lines (55 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
char in[60];
int count[26];
for(int i=0;i<26;i++)
count[i]=0;
scanf("%s",in);
while(in[0]!='#'){
int e;
for(int i=0;i<60;i++){
if(in[i]>'z'||in[i]<'a'){
e=i-1;
break;
}
}
for(int i=0;i<26;i++)
count[i]=0;
char pre;
int i;
for(i=e;i>=0;i--){
count[in[i]-'a']++;
if(i==e)pre=in[i];
else{
if(in[i]<pre)break;
pre=in[i];
}
}
if(i>=0){
char c=in[i];
in[i]=0;
printf("%s",in);
for(int j=c-'a'+1;j<26;j++){
if(count[j]){
cout<<char(j+'a');
count[j]--;
break;
}
}
for(int j=0;j<26;j++){
while(count[j]){
cout<<char(j+'a');
count[j]--;
}
}
cout<<endl;
}
else{
cout<<"No Successor"<<endl;
}
scanf("%s",in);
}
return 0;
}