Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/* include needed headers here*/
using namespace std;
typedef map<char, int> pmap;
typedef map<int, char> vmap;
void main()
{
int T; //test cases
//freopen("C:\\input.txt","r",stdin);
//freopen("C:\\ouput.out","w",stdout);
cin >> T;
for (int l = 0; l < T; l++) //for each test cases
{
string inp, S, D, stm;
char d, e, f, h, g[5], num[1000];
int k, i, j, y, N, M, t, mod, r = 0, m;
long int ss, z = 0, p;
double x;
pmap source;
vmap dest;
cin >> inp;
cin >> S;
cin >> D;
N = S.size();
M = D.size();
t = inp.size();
for (i = 0; i < S.size(); i++) {
d = S.at(i);
source[d] = i;
}
for (j = 0; j < D.size(); j++)
e = D.at(j);
dest[j] = e;
}
for (k = 0; k < inp.size(); k++) {
f = inp.at(k);
y = source[f];
ss = pow(N, t - 1);
z += y * ss;
t--;
}
i = 0;
do {
x = z / M;
mod = z % M;
p = pow(10, i);
r += mod * p;
z = floor(x);
i++;
} while (z != 0);
sprintf(num, "%d", r);
cout << "Case #" << l + 1 << ":";
for (i = 0; i < strlen(num); i++) {
g[0] = num[i];
m = atoi(g);
h = dest[m];
cout << h;
}
cout << endl;
}
}
//end coding by jeho
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment