-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertionupto36base.cpp
More file actions
63 lines (62 loc) · 1.1 KB
/
convertionupto36base.cpp
File metadata and controls
63 lines (62 loc) · 1.1 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
59
60
61
62
63
#include <bits/stdc++.h>
using namespace std;
int chartoint(char c){
int d;
if((int)c>64&&(int)c<91){
d=(int)c-55;
}
else if((int)c>47&&(int)c<58){
d=(int)c-48;
}
return d;
}
long long systodec(string liczba,int system){
long long w=chartoint(liczba[0]);
char c;
int d;
for(int i=1;i<liczba.size();i++)
{
d = chartoint(liczba[i]);
w = w * system + d;
}
return w;
}
string dectosys(long long dec,int system2){
string jakastam="";
int res;
char znak;
int d;
while(dec>0)
{
res = dec % system2;
if (res > 9)
{
d=res+55;
znak=(char)d;
}
else
{
d=res+48;
znak=(char)d;
}
dec = dec/system2;
jakastam+=znak;
}
return jakastam;
}
string ferocious(string s){
stringstream cc;
cc << s;
string f(cc.str());
string z(f.rbegin(), f.rend());
return z;
}
int main() {
string gramburger;
cin>>gramburger;
int system1,system2;
cin>>system1>>system2;
long long decimalnum=systodec(gramburger,system1);
cout<<ferocious(dectosys(decimalnum,system2));
return 0;
}