-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.cpp
50 lines (43 loc) · 1.03 KB
/
main.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
49
50
// Author : Qi Zhang
// Date : 2018-12-11
#include <bits/stdc++.h>
using namespace std;
vector<string> mysplit(string &s, char t){
vector<string> info;
string cur;
for(auto c: s){
if(c == t){
if(cur != "") info.push_back(cur);
cur = "";
}
else cur += c;
}
if(cur != "") info.push_back(cur);
return info;
}
int main()
{
string line;
while (getline(cin, line)) {
vector<string> tmp = mysplit(line, ' ');
string x = tmp[0];
int p1 = stoi(tmp[1]), p2 = stoi(tmp[2]);
int com = 0, d = 1;
for(int i = x.size()-1; i >= 0; i--){
char c = x[i];
int digit = (c >= '0' && c <= '9'? c-'0': c-'a'+10);
com += digit * d;
d *= p1;
}
string y;
while(com){
int r = com % p2;
char c = (r < 10? '0'+r: 'a'+r-10);
y += c;
com /= p2;
}
reverse(y.begin(), y.end());
cout << y << endl;
}
return 0;
}