슈콩

[프로그래머스] Lv.2 [3차] n진수 게임 본문

Algorithms/Programmers

[프로그래머스] Lv.2 [3차] n진수 게임

shukong 2025. 10. 16. 17:27

 

 

[문제]

https://school.programmers.co.kr/learn/courses/30/lessons/17687#qna

 

프로그래머스

SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

 

[소스 코드]

class Solution {
    public String solution(int n, int t, int m, int p) {
        String answer = "";
        int num = 0;
        int order = 1;
        int cnt = 0;
        while(cnt<t){
            String currNum = Integer.toString(num,n).toUpperCase();
            for(char c : currNum.toCharArray()){
                if(order==m+1) order = 1;
                if(p==order){
                    answer += c;
                    cnt++;
                    if(cnt==t) break;
                }
                order++;
            }
            num++;
        }
        return answer;
    }
}