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;
}
'<algorithm> > 프로그래머스' 카테고리의 다른 글
프로그래머스 게임 맵 최단거리 c++ (dfs, bfs) (0) | 2023.08.31 |
---|---|
프로그래머스 단어 변환 c++ (0) | 2023.08.30 |
프로그래머스 압축 c++ (4) | 2023.08.07 |
프로그래머스 이중우선순위큐 c++ (0) | 2023.08.06 |
프로그래머스 야근 지수 c++ (0) | 2023.07.30 |