-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ40.cpp
More file actions
58 lines (52 loc) · 1.11 KB
/
Copy pathQ40.cpp
File metadata and controls
58 lines (52 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <string>
#include <vector>
#include <map>
#include <iostream>
using namespace std;
map<int, string> match;
void initMatch() {
for (int i = 0; i < 10; i++) {
match[i] = to_string(i);
}
match[10] = "A";
match[11] = "B";
match[12] = "C";
match[13] = "D";
match[14] = "E";
match[15] = "F";
}
string calcArithmetic(int n, int number) {
string result = "";
if (number == 0) {
return "0";
}
while (number > 0) {
result = match[number % n] + result;
number /= n;
}
return result;
}
string solution(int n, int t, int m, int p) {
string answer = "";
initMatch();
int count = 0;
int num = 0;
vector<char> nums;
while (nums.size() < t) {
string transform = calcArithmetic(n, num);
for (char arith: transform) {
if (count % m + 1 == p) {
nums.push_back(arith);
}
count++;
if (nums.size() >= t) {
break;
}
}
num++;
}
for (char n: nums) {
answer += n;
}
return answer;
}