https://programmers.co.kr/learn/courses/30/lessons/17687
코딩테스트 연습 - [3차] n진수 게임
N진수 게임 튜브가 활동하는 코딩 동아리에서는 전통적으로 해오는 게임이 있다. 이 게임은 여러 사람이 둥글게 앉아서 숫자를 하나씩 차례대로 말하는 게임인데, 규칙은 다음과 같다. 숫자를 0
programmers.co.kr
#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 |