forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaliennumbers.cpp
48 lines (36 loc) · 1000 Bytes
/
aliennumbers.cpp
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
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int getValue(char s, string& source) {
for(int i = 0; i < source.size(); i++) {
if(source[i] == s) {
return i;
}
}
return 0;
}
int main() {
int n;
cin >> n;
for(int i = 0; i < n; i++) {
cout << "Case #" << i+1 << ": ";
string number, source, target;
cin >> number >> source >> target;
int sizeS = source.length();
int sizeT = target.length();
reverse(number.begin(), number.end());
long long representation = 0;
for(int j = 0; j < number.size(); j++) {
representation += getValue(number[j], source) * pow(sizeS, j);
}
string ret = "";
while(representation > 0) {
ret += target[representation % sizeT];
representation /= sizeT;
}
reverse(ret.begin(), ret.end());
cout << ret << endl;
}
}