[백준]5622번: 다이얼(Java)

ywwwon01·2022년 7월 14일
0

알고리즘

목록 보기
3/13

문제

🔗 5622번: 다이얼

첫 번째 시도

code

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        String temp;
        int howMuch = 0;

        temp = br.readLine();

        for (int i = 0; i < temp.length(); i++) {
            if (temp.charAt(i) == 'A' || temp.charAt(i) == 'B' || temp.charAt(i) == 'C') {
                howMuch += 3;
            }
            else if (temp.charAt(i) == 'D' || temp.charAt(i) == 'E' || temp.charAt(i) == 'F') {
                howMuch += 4;
            }
            else if (temp.charAt(i) == 'G' || temp.charAt(i) == 'H' || temp.charAt(i) == 'I') {
                howMuch += 5;
            }
            else if (temp.charAt(i) == 'J' || temp.charAt(i) == 'K' || temp.charAt(i) == 'L') {
                howMuch += 6;
            }
            else if (temp.charAt(i) == 'M' || temp.charAt(i) == 'N' || temp.charAt(i) == 'O') {
                howMuch += 7;
            }
            else if (temp.charAt(i) == 'P' || temp.charAt(i) == 'Q' || temp.charAt(i) == 'R' || temp.charAt(i) == 'S') {
                howMuch += 8;
            }
            else if (temp.charAt(i) == 'T' || temp.charAt(i) == 'U' || temp.charAt(i) == 'V') {
                howMuch += 9;
            }
            else {
                howMuch += 10;
            }
        }
        bw.write(String.valueOf(howMuch));
        bw.flush();
    }
}

review

그런데 이것이 정말 최선이었을까요?

이런.. 조건문 지옥의 방법밖에 없었을까요?

일단 맞기는 했으니..

구글링 하러 떠납니다..

오늘의 실수..💦

..

Stringchar

잘 구분하고..

잘 쓰는 인간으로 거듭나자..

이상입니다.

profile
생각의 전개를 공유합니다.

0개의 댓글