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 |
Tags
- Error fetching remote repo 'origin'
- 투에모스문자열
- CMD
- 자바
- jenkins
- 이클립스
- docker
- 호석이두마리치킨
- 소가길을건너간이유6
- to display the conditions report re-run your application with 'debug' enabled
- 날짜일수
- 20055
- Error
- 이산수학
- 별자리 만들기
- EC2
- Eclipse
- 알고리즘
- Java
- 14466
- 18222
- 백준
- 설정
- SpringBoot
- 21278
- documentationpluginsbootstrapper
- dockercompose
- 2108_통계학
- 프로그래머스
- 2167. 2차원 배열의 합
Archives
- Today
- Total
계단을 오르듯이
20436. ZOAC3 본문
package september.twoweek;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class B_20436_ZOAC3 {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
Map<Character, int[]> keyboard = new HashMap<>();
keyboard.put('q', new int[] { 0, 0, 0 }); // 위치 y,x/좌우확인
keyboard.put('w', new int[] { 0, 1, 0 });
keyboard.put('e', new int[] { 0, 2, 0 });
keyboard.put('r', new int[] { 0, 3, 0 });
keyboard.put('t', new int[] { 0, 4, 0 });
keyboard.put('y', new int[] { 0, 5, 1 });
keyboard.put('u', new int[] { 0, 6, 1 });
keyboard.put('i', new int[] { 0, 7, 1 });
keyboard.put('o', new int[] { 0, 8, 1 });
keyboard.put('p', new int[] { 0, 9, 1 });
keyboard.put('a', new int[] { 1, 0, 0 });
keyboard.put('s', new int[] { 1, 1, 0 });
keyboard.put('d', new int[] { 1, 2, 0 });
keyboard.put('f', new int[] { 1, 3, 0 });
keyboard.put('g', new int[] { 1, 4, 0 });
keyboard.put('h', new int[] { 1, 5, 1 });
keyboard.put('j', new int[] { 1, 6, 1 });
keyboard.put('k', new int[] { 1, 7, 1 });
keyboard.put('l', new int[] { 1, 8, 1 });
keyboard.put('z', new int[] { 2, 0, 0 });
keyboard.put('x', new int[] { 2, 1, 0 });
keyboard.put('c', new int[] { 2, 2, 0 });
keyboard.put('v', new int[] { 2, 3, 0 });
keyboard.put('b', new int[] { 2, 4, 1 });
keyboard.put('n', new int[] { 2, 5, 1 });
keyboard.put('m', new int[] { 2, 6, 1 });
StringTokenizer st = new StringTokenizer(in.readLine(), " ");
char SL = st.nextToken().charAt(0);
char SR = st.nextToken().charAt(0);
String str = in.readLine();
int size = str.length();
int result = size; // 클릭할 때 시간 1 이므로 길이만큼의 시간을 먼저 더한다.
for (int i = 0; i < size; i++) {
char alpha = str.charAt(i);
int[] now = keyboard.get(alpha);
if (now[2] == 0) { // 왼쪽 손
int[] left = keyboard.get(SL);
result += Math.abs(left[0] - now[0]) + Math.abs(left[1] - now[1]);
SL = alpha;
} else { // 오른쪽 손
int[] right = keyboard.get(SR);
result += Math.abs(right[0] - now[0]) + Math.abs(right[1] - now[1]);
SR = alpha;
}
}
System.out.println(sb.append(result));
}
}
'알고리즘 > 백준_JAVA' 카테고리의 다른 글
20154. 이 구역의 승자는 누구야 (0) | 2021.12.31 |
---|---|
1912. 연속합 (0) | 2021.12.31 |
20291. 파일 정리 (0) | 2021.12.30 |
21318. 피아노 체조 (0) | 2021.12.30 |
16954. 움직이는 미로 탈출 (0) | 2021.12.30 |