https://programmers.co.kr/learn/courses/30/lessons/17687
#include <string>
#include <vector>
#include <iostream>
using namespace std;
string changeToN(int n, int num) {
string result = "";
while (num) {
string c;
if (n > 11 && num % n >= 10) {
c = 'A' + (num % n - 10);
}
else {
c = to_string(num % n);
}
result = c + result;
num /= n;
}
return result.size() < 1 ? "0" : result;
}
string solution(int n, int t, int m, int p) {
string answer = "";
int count = 0;
for (int i = 0; i < 100000; i++) {
string num = changeToN(n, i);
for (char c : num) {
if (answer.size() == t) return answer;
if (count % m == p-1) {
answer.push_back(c);
}
count++;
}
}
return answer;
}
'전공공부 > 코딩테스트' 카테고리의 다른 글
(c++) 백준 "2564. 경비원" (0) | 2022.05.02 |
---|---|
(c++) 프로그래머스 "n^2 배열 자르기" (0) | 2022.05.02 |
(c++) 백준 "10157. 자리배정" (0) | 2022.05.01 |
(c++) 프로그래머스 "다음 큰 숫자" (0) | 2022.05.01 |
(c++) 프로그래머스 "배달" (0) | 2022.04.30 |