프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이방법
0부터 t x m까지의 숫자를 n진법으로 변환해서 temp에 더한다. 이후 temp에서 튜브가 말해야 하는 숫자들만 구해서 answer에 담아 리턴한다.
#include <string>
#include <vector>
using namespace std;
string convert(int n, int num) {
char list[] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
string temp = "";
while(num / n != 0) {
temp = list[num % n] + temp;
num /= n;
}
temp = list[num % n] + temp;
return temp;
}
string solution(int n, int t, int m, int p) {
string answer = "";
string temp = "";
int count = 0;
for(int i = 0; i < t * m; i++) temp += convert(n, i);
for(int i = p - 1; i < temp.length(), count < t; i += m, count++;)
answer += temp[i];
return answer;
}
'프로그래머스 > 2레벨' 카테고리의 다른 글
게임 맵 최단거리/C++ (0) | 2023.02.13 |
---|---|
2개 이하로 다른 비트/C++ (0) | 2023.02.10 |
숫자 블럭/C++ (0) | 2023.02.08 |
점 찍기/C++ (0) | 2023.02.08 |
오픈채팅방/C++ (0) | 2023.02.08 |