-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNums_Spelling.java
More file actions
40 lines (35 loc) · 883 Bytes
/
Copy pathNums_Spelling.java
File metadata and controls
40 lines (35 loc) · 883 Bytes
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
package programmers;
public class Nums_Spelling {
public static void main(String[] args) {
Solution5 s1 = new Solution5();
String s = "one4seveneight";
// String s = "123";
s1.solution(s); //1478
// 0 zero
// 1 one
// 2 two
// 3 three
// 4 four
// 5 five
// 6 six
// 7 seven
// 8 eight
// 9 nine
}
}
class Solution5 {
public int solution(String s) {
// 만약 숫자밖에 없다면 그 자체를 return
if(s.length() == 0) {
return Integer.valueOf(s);
}
String[] spell_list = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
for(int i = 0; i<spell_list.length; i++) {
if(s.contains(spell_list[i])) {
s = s.replaceAll(spell_list[i], i+"");
}
}
int answer = Integer.valueOf(s);
return answer;
}
}