-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path20220628.java
More file actions
39 lines (35 loc) · 1.3 KB
/
20220628.java
File metadata and controls
39 lines (35 loc) · 1.3 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
String[] strings = br.readLine().replace(",","").replace(";","").split(" ");
String type = strings[0];
for (int i = 1; i < strings.length; i++) {
String result = type;
String[] split = strings[i].split("");
for (int j = split.length - 1; j >= 0; j--) {
if (split[j].equals("*") || split[j].equals("&")) {
result += split[j];
continue;
} else if (split[j].equals("]")) {
result += "[";
continue;
} else if (split[j].equals("[")) {
result += "]";
continue;
} else {
result += " ";
for (int k = 0; k <= j; k++) {
result += split[k];
}
break;
}
}
sb.append(result).append(";").append("\n");
}
System.out.println(sb);
}
}