티스토리 뷰
1. Java 구현
import java.util.Scanner; public class Main { public static void main(String[] args) { /* 2018.08.08 */ Scanner sc = new Scanner(System.in); String input = sc.nextLine(); // UNUCIC는 868242 A == 65 int[] phone = { 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10 }; printResult(phone, input); } public static void printResult(int[] arr, String input) { int result = 0; for(int i = 0; i < input.length(); i++) { int idx = (int)(input.charAt(i)) - 65; result += arr[idx]; } System.out.println(result); } }
'알고리즘 > BaekJoon 알고리즘' 카테고리의 다른 글
[백준 알고리즘] Q10989 수 정렬하기 3 -Counting Sort (계수 정렬) (1) | 2018.10.12 |
---|---|
[백준 알고리즘] Q2941 크로아티아 알파벳 (0) | 2018.10.11 |
[백준 알고리즘] Q2908 상수 (0) | 2018.10.11 |
[백준 알고리즘] Q1152 단어의 개수 (0) | 2018.10.11 |
[백준 알고리즘] Q1316 그룹 단어 체커 (0) | 2018.10.11 |