Why even if my logic seems complete it’s unable to pass the test case for the below given problem “Predict The Message” from the recent contest "krack the code " ?
#include <bits/stdc++.h>
#define mcc unordered_map<char,char>
using namespace std;
void setIO() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
string base_change(const string& n,int from,int to) {
int d = 0;
int p = 1;
for(int i = n.size() - 1;i >= 0;i--) {
int di = isdigit(n[i]) ? (n[i] - '0') : (n[i] - 'A' + 10);
d += di * p;
p *= from;
}
string res = "";
while (d > 0) {
int r = d % to;
char digit = (r < 10) ? (r + '0') : (r - 10 + 'A');
res = digit + res;
d /= to;
}
return res;
}
int main() {
setIO();
int t;
cin >> t;
mcc p{{'0','A'},{'1','B'},{'2','C'},{'3','D'},{'4','E'},{'5','F'},{'6','G'},{'7','H'},{'8','I'},{'9','J'},{'A','K'},{'B','L'},{'C','M'},{'D','N'},{'E','O'},{'F','P'},{'G','Q'},{'H','R'},{'I','S'},{'J','T'},{'K','U'},{'L','V'},{'M','W'},{'N','X'}, {'O','Y'},{'P','Z'};
while(t--) {
int n,k,q;
cin >> n >> k >> q;
string s = base_change(to_string(q-1),10,k);
string A(n-s.size(),'A');
cout << A;
for(char c : s) cout << p[c];
cout << '\n';
}
return 0;
}