Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- array
- Counting
- 코딩테스트
- hash table
- Binary Search
- simulation
- bit manipulation
- Binary Tree
- Number Theory
- database
- implement
- geometry
- Data Structure
- java
- string
- SQL
- greedy
- Matrix
- Class
- two pointers
- 파이썬
- Math
- dynamic programming
- 구현
- 자바
- Stack
- sorting
- Method
- 코테
- Tree
Archives
- Today
- Total
코린이의 소소한 공부노트
[프로그래머스/Lv.0] 영어가 싫어요 본문
1. Input
1) 문자열 numbers
2. Output
1) numbers를 정수로 바꿔서 반환
3. Constraint
1) numbers는 소문자로만 구성되어 있다.
2) numbers는 "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" 들이 공백 없이 조합되어 있다.
3) 1 ≤ numbers의 길이 ≤ 50
4) "zero"는 numbers의 맨 앞에 올 수 없다.
4. Example
Input: number="onefourzerosixseven" -> Output: 14067
5. Code
1) 첫 코드(2022/10/31)
import java.util.ArrayList;
// main()
ArrayList<Integer> list = new ArrayList<Integer>();
for(int i=0 ; i<numbers.length() ; i++){
char c = numbers.charAt(i);
if(c=='z') { list.add(0); i+=3; }
else if(c=='o') { list.add(1); i+=2; }
else if(c=='e') { list.add(8); i+=4; }
else if(c=='n') { list.add(9); i+=3; }
else if(c=='t'){
if(numbers.substring(i,i+2).equals("tw")) { list.add(2); i+=2; }
else { list.add(3); i+=4; }
}
else if(c=='f'){
if(numbers.substring(i,i+2).equals("fo")) list.add(4);
else list.add(5);
i+=3;
}
else{
if(numbers.substring(i,i+2).equals("si")) { list.add(6); i+=2; }
else { list.add(7); i+=4; }
}
}
long answer = 0;
for(int i=0 ; i<list.size() ; i++)
answer += list.get(i) * Math.pow(10,list.size()-1-i);
return answer;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[프로그래머스/Lv.0] 한 번만 등장한 문자 (0) | 2022.10.31 |
---|---|
[프로그래머스/Lv.0] 인덱스 바꾸기 (0) | 2022.10.31 |
[프로그래머스/Lv.0] 대문자와 소문자 (0) | 2022.10.28 |
[프로그래머스/Lv.0] 암호 해독 (0) | 2022.10.28 |
[프로그래머스/Lv.0] 369게임 (0) | 2022.10.28 |