-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathUVa00146_IDCodes.java
More file actions
47 lines (40 loc) · 1.4 KB
/
UVa00146_IDCodes.java
File metadata and controls
47 lines (40 loc) · 1.4 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
package uva;
/* USER: 46724 (sfmunera) */
/* PROBLEM: 82 (146 - ID Codes) */
/* SUBMISSION: 08574488 */
/* SUBMISSION TIME: 2011-02-13 05:34:52 */
/* LANGUAGE: 2 */
import java.util.*;
public class UVa00146_IDCodes {
public static void main(String[] args) {
try {
Scanner in = new Scanner(System.in);
while (true) {
char[] str = in.nextLine().toCharArray();
if (String.valueOf(str).equals("#")) break;
int k = -1;
for (int i = 0; i < str.length - 1; ++i)
if (str[i] < str[i + 1]) k = i;
if (k == -1) {
System.out.println("No Successor");
continue;
}
int l = 0;
for (int i = k + 1; i < str.length; ++i)
if (str[k] < str[i]) l = i;
char tmp = str[k];
str[k] = str[l];
str[l] = tmp;
for (int i = k + 1; i < (str.length + k + 1) / 2; ++i) {
tmp = str[i];
str[i] = str[str.length - i + k];
str[str.length - i + k] = tmp;
}
System.out.println(String.valueOf(str));
}
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
}