-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem50.java
69 lines (57 loc) · 1.51 KB
/
Problem50.java
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
64
65
66
67
68
69
package dimikOJ;
import java.util.Scanner;
public class Problem50 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int T = input.nextInt();
while (T < 1) {
T = input.nextInt();
}
input.nextLine();
String[] inputs = new String[T];
for (int i = 0; i < inputs.length; i++) {
String temp = input.nextLine();
int length = temp.length();
while (length > 50 || !isDigit(temp.charAt(0)) || !isDigit(temp.charAt(temp.length() - 1))
|| !isValid(temp)) {
temp = input.nextLine();
length = temp.length();
}
inputs[i] = temp;
}
input.close();
for (int i = 0; i < inputs.length; i++) {
StringBuilder myString = new StringBuilder(inputs[i]);
for (int j = 1; j < myString.length() - 1; j++) {
if (myString.charAt(j) == 'R') {
myString.setCharAt(j, myString.charAt(j + 1));
} else if (myString.charAt(j) == 'L') {
myString.setCharAt(j, myString.charAt(j - 1));
}
}
System.out.println(myString);
}
}
static boolean isDigit(char m) {
if (m >= 48 && m <= 57) {
return true;
} else {
return false;
}
}
static boolean isValid(String s) {
boolean res = true;
for (int i = 1; i < s.length() - 1; i++) {
if (s.charAt(i) == 'R' || s.charAt(i) == 'L') {
if (isDigit(s.charAt(i - 1)) && isDigit(s.charAt(i + 1))) {
res = true;
} else {
res = false;
return res;
}
}
}
return res;
}
}