Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

21.06.30 - [PG] 124 나라의 숫자 #100

Closed
suhyunsim opened this issue Jun 30, 2021 · 0 comments
Closed

21.06.30 - [PG] 124 나라의 숫자 #100

suhyunsim opened this issue Jun 30, 2021 · 0 comments
Assignees
Labels
lv.2 프로그래머스 - level 2 수학 수학 실패 시도했지만 맞지 못한 문제

Comments

@suhyunsim
Copy link
Owner

문제

핵심 아이디어

어려운 점, 실수

  • 아이디어가 떠오르지 않아서 포기했다.
  • String numbers = {"4", "1", "2"}; 3으로 나눈 나머지가 1 ,2, 0이 된다는 점에서 numbers[1], numbers[2], numbers[0] 이렇게 적용
  • 3의 배수일 때는 3으로 나눈 몫에 1을 더 빼준다.
  • StringBuildier의 insert를 사용하면 앞에다가 계속 붙여나갈 수 있다.(append는 뒤에 붙임)

풀이

package main.java.com.poogle.PG.Q12899;


public class Solution {
    public static String solution(int n) {
        String[] numbers = {"4", "1", "2"};
        StringBuilder answer = new StringBuilder();
        while (n > 0) {
            int remainder = n % 3;
            n /= 3;
            if (remainder % 3 == 0) n--;

            answer.insert(0, numbers[remainder]);
        }
        return answer.toString();
    }

    public static void main(String[] args) {
        System.out.println(solution(5));
        System.out.println(solution(9));
        System.out.println(solution(10));
    }
}
@suhyunsim suhyunsim added 실패 시도했지만 맞지 못한 문제 수학 수학 lv.2 프로그래머스 - level 2 labels Jun 30, 2021
@suhyunsim suhyunsim added this to the 7월 1주 차 milestone Jun 30, 2021
@suhyunsim suhyunsim self-assigned this Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lv.2 프로그래머스 - level 2 수학 수학 실패 시도했지만 맞지 못한 문제
Projects
None yet
Development

No branches or pull requests

1 participant