본문 바로가기

프로그래머스/lv0

외계행성의 나이

/* 외계행성의 나이
 * ROGRAMMERS-962 행성에서는 나이를 알파벳으로 말하고 있습니다.
 * a는 0, b는 1, c는 2, ..., j는 9입니다.
 * 예를 들어 23살은 cd, 51살은 fb로 표현합니다.
 * 나이 age가 매개변수로 주어질 때 PROGRAMMER-962식 나이를 return
 *
 * age  result
 * 23   "cd"
 * 51   "fb"
 * 100  "baa"
 */

 

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
public class programmer_0_72 {
    static int a1 = 23;
    static int a2 = 51;
    static int a3 = 100;
    public String solution(int age) {
        String answer = "";
        String[] aAge = {"a""b""c""d""e""f""g""h""i""j"};
        String[] ar = Integer.toString(age).split("");
        for(String n : ar){
            answer += aAge[Integer.parseInt(n)];
        }
        return answer;
    }
    public static void main(String args[]){
        programmer_0_72 t = new programmer_0_72();
 
        System.out.println("---------------------------------------");
        System.out.println("result = " + t.solution(a1));
        System.out.println("---------------------------------------");
        // System.out.println("result2 = " + t.solution(a2));
        // System.out.println("---------------------------------------");
        // System.out.println("result3 = " + t.solution(a3));
        // System.out.println("---------------------------------------");
    }
}
cs

'프로그래머스 > lv0' 카테고리의 다른 글

가위 바위 보  (0) 2022.12.02
문자열 정렬하기 (1)  (0) 2022.12.02
진료순서 정하기  (0) 2022.12.02
모스부호 (1)  (2) 2022.12.02
구슬을 나누는 경우의 수  (2) 2022.12.02