☞ 문제

 

 

 

☞ 코드

 

 

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
package algo02;
 
import java.util.Scanner;
 
public class Country124 {
    
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        System.out.println("원하는 숫자를 입력해주세요.");
        int n = sc.nextInt();
        System.out.println(solution(n));
    }
    
    public static String solution(int n) {
        
        String answer = "";
        int remainder = 0;        //나머지
        
        while(n > 0) {            
            remainder = n % 3;    //3으로 나눈 나머지
            n = n / 3;            //3으로 나눈 몫
            
            if(remainder == 0) {        // ex) 3일 때
                n -= 1;
                remainder = 4;
            }
            answer = remainder + answer;
        }
        
        return answer;
    }
 
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
 

 

 

생각만 잘 하면 괜찮은 문제인데 생각하는 게 넘 어려웠다....

 

그나저나....

지금 jre 파일 때문에 컴파일이 안 돼서 실행을 못 한다.....

그래서 프로그래머스에서 돌려봤는데 잘 된다.....

근데 컴파일이 아예 안 돼서 빨리 고쳐야겠다.... 큰일이다...............

'Algorithm' 카테고리의 다른 글

모의고사  (1) 2019.05.12
예산  (1) 2019.05.03
콜라츠 추측  (0) 2019.04.28
시저 암호  (1) 2019.04.25
나누어 떨어지는 숫자 배열  (2) 2019.04.22

+ Recent posts