그럴듯한 개발 블로그
반응형

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

문제 이해가 오래걸렸다. 오랜만에 푸니까 더 오래 걸린 것 같다. 

#include <string>
#include <vector>
#include <algorithm>

using namespace std;
vector<char>    numArr;

string getStringValue(int value, int n) { // n == 진법
    string res = "";
    if (value == 0)
        res += '0';
    while (value) {
        res += numArr[value % n];
        value /= n;
    }
    reverse(res.begin(), res.end());
    return (res);
}


string solution(int n, int t, int m, int p) {
    // 진법 n, 미리 구할 숫자의 갯수 t, 게임에 참가하는 인원 m, 튜브의 순서 p
    numArr = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
    string game = "", res = "";
    int value = 0;
    while (game.size() < t * m)
        game += getStringValue(value++, n);
    for (int i = 0; i < t; i++)
        res += game[i * m + p - 1];
    return res;
}

 

반응형
profile

그럴듯한 개발 블로그

@donghyk2

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!