2018 KAKAO BLIND RECRUITMENT (2018 카카오 블라인드 채용 문제)
N진수로 수를 한글자씩 셀 때 자신의 차례마다 어떤 숫자를 불러야하는지 출력하는 문제입니다.
1. 인원 * 말해야하는 숫자 개수 만큼 N진수로 수를 구해서 string안에 담습니다.
ex) 인원 3, 말해야하는 숫자 2개, 2진수
0, 1, 10, 11, 100, 101
cout << str;
// 011011100101
while (num / n != 0)
{
temp = num % n;
value = arr[temp] + value;
num /= n;
}
value = arr[num % n] + value;
2. (튜브의 순서 - 1) + (멤버수 * 몇번째 반복)
for (int i = 0; i < t; ++i)
{
pos = p - 1 + (m * i);
answer += temp[pos];
}
코드
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
string changeNumber(int n, int num)
{
int temp;
string value;
string arr[16] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"};
while (num / n != 0)
{
temp = num % n;
value = arr[temp] + value;
num /= n;
}
value = arr[num % n] + value;
return value;
}
string solution(int n, int t, int m, int p)
{
int pos = p - 1;
string answer = "";
string temp;
for (int i = 0; i < t * m; ++i)
{
temp += changeNumber(n, i);
}
for (int i = 0; i < t; ++i)
{
pos = p - 1 + (m * i);
answer += temp[pos];
}
return answer;
}
'알고리즘' 카테고리의 다른 글
[C++] 백준 4358번 생태학 (0) | 2021.08.04 |
---|---|
[C++] 프로그래머스 - 압축 (0) | 2021.05.26 |
[C++] 프로그래머스 - 캐시 (0) | 2021.05.14 |
[C++] 프로그래머스 - 프렌즈 4블록 (0) | 2021.05.14 |
[C++] 프로그래머스 - 뉴스 클러스터링 (0) | 2021.05.14 |