-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathe2020_3.java
More file actions
51 lines (37 loc) · 1.24 KB
/
e2020_3.java
File metadata and controls
51 lines (37 loc) · 1.24 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
package org.codingTest;
import java.util.HashMap;
public class e2020_3 {
public static void main(String[] args) {
// 이메일 주소 만들기
String S = "John Don; Peter Benjia Parke; Peter Benjia Parke; Marry Jane Waston-Parkek; John hey Don";
String C = "Example";
StringBuilder answer = new StringBuilder();
String email = "@"+C.toLowerCase()+".com";
String[] names = S.split("; ");
HashMap<String, Integer> hm = new HashMap<>();
for(String name:names) {
int nameCount = 1;
String original = name;
name = name.toLowerCase();
String[] namePart = name.replace("-", "").split(" ");
String newName = namePart[namePart.length-1] + "_" + namePart[0];
if(hm.containsKey(newName)) {
nameCount = hm.get(newName)+1;
hm.replace(newName, nameCount);
}
else {
hm.put(newName, nameCount);
}
//System.out.println("original = "+name);
if(nameCount > 1)
newName += nameCount;
//System.out.println("new = "+newName);
if(answer.length() > 0)
answer.append("; ");
answer.append(original + " <"+newName+email+">");
//answer.append(name);
}
System.out.println(answer);
String emailStr = answer.toString();
}
}