Repository navigation
Expand file tree
/
Copy pathSolution.java
More file actions
97 lines (89 loc) · 2.02 KB
/
Copy pathSolution.java
File metadata and controls
97 lines (89 loc) · 2.02 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static String processE(String line) {
StringBuilder temp = new StringBuilder();
boolean process_flag = false;
for (int i = line.length() - 1; i >= 3; i--) {
char ch = line.charAt(i);
if (process_flag) {
temp.insert(0, ch);
break;
} else {
temp.insert(0, ch);
}
if (ch == '@') {
process_flag = true;
}
}
for (int i = 0; i < 5; i++) {
temp.insert(0, "*");
}
temp.insert(0, line.charAt(2));
temp.insert(0, "E:");
return temp.toString();
}
static String processP(String line) {
StringBuilder temp = new StringBuilder();
int i = line.length() - 1;
for (; i >= line.length() - 4; i--) {
char ch = line.charAt(i);
temp.insert(0, ch);
}
int cnt = 6;
temp.insert(0, "***-***-");
for (; i >= 2; i--) {
char ch = line.charAt(i);
if (ch >= '0' && ch <= '9') {
--cnt;
if (cnt == 0) {
--i;
break;
}
}
}
boolean process_flag = true;
for (; i >= 2; i--) {
char ch = line.charAt(i);
if (ch >= '0' && ch <= '9') {
temp.insert(0, "*");
process_flag = true;
} else if (ch == '+') {
temp.insert(0, ch);
process_flag = true;
} else {
if (process_flag) {
temp.insert(0, "-");
process_flag = false;
}
}
}
if (temp.toString().startsWith("-")) {
temp.deleteCharAt(0);
}
temp.insert(0, "P:");
return temp.toString();
}
public static void main(String args[]) throws Exception {
Scanner scan = new Scanner(System.in);
String line = null;
StringBuilder sBuilder = new StringBuilder();
while (scan.hasNextLine()) {
line = scan.nextLine();
if (line.length() == 0) {
break;
}
if (line.startsWith("E")) {
sBuilder.append(processE(line)).append("\n");
} else if (line.startsWith("P")) {
sBuilder.append(processP(line)).append("\n");
}
}
sBuilder.setLength(sBuilder.length() - 1);
scan.close();
System.out.println(sBuilder.toString());
}
}