본문 바로가기

Studying JAVA/백준

[7단계]문자열 사용하기-5622번 다이얼

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
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        int time=0;
 
        for(int i=0;i<S.length();i++){
            switch(S.charAt(i)){
                case 'A'case 'B'case 'C':
                    time+=2;
                    break;
                case 'D'case 'E'case 'F':
                    time+=3;
                    break;
                case 'G'case 'H'case 'I':
                    time+=4;
                    break;
                case 'J'case 'K'case 'L':
                    time+=5;
                    break;
                case  'M'case  'N'case  'O':
                    time+=6;
                    break;
                case 'P'case 'Q'case  'R'case 'S':
                    time+=7;
                    break;
                case  'T'case  'U'case  'V':
                    time+=8;
                    break;
                case  'W'case  'X'case  'Y'case  'Z':
                    time+=9;
                    break;
                default :
                    break;
            }   
            time+=1;
        }
        System.out.println(time);
    }
}
cs