/// Header file begin
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<string>
#include<vector>
#include<cmath>
#include<cctype>
#include<sstream>
#include<set>
#include<list>
#include<stack>
#include<utility>
#include<queue>
#include<algorithm>
#include<cstdlib>
/// End
//..........
/// Macro
#define sf scanf
#define pf printf
#define lp1(i,n) for(i=0;i<n;i++)
#define lp2(i,n) for(i=1;i<=n;i++)
#define mem(c,v) memset(c,v,sizeof(c))
#define cp(a) cout<<" "<<a<<" "
#define nl puts("")
#define sq(x) ((x)*(x))
#define all(x) x.begin(),x.end()
#define reall(x) x.rbegin(),x.rend()
#define sz size()
#define gc getchar()
#define pb push_back
#define freader freopen("input.txt","r",stdin)
/// End.........
/// Size
#define mx7 20000100
#define mx6 1500000
#define mx5 100005
#define mx4 1000100
#define inf 1<<30 //infinity value
#define eps 1e-9
#define mx (65540)
#define mod 1000000007
#define pi acos(-1.0)
/// Macros for Graph
#define white 1
#define gray 2
#define black 3
#define nil 0
using namespace std;
/***************/
/// typedef
typedef long long LL;
typedef long L;
typedef unsigned long long ull;
typedef unsigned long ul;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef vector<int>vi;
typedef vector<long long> vll;
typedef vector<long>vl;
typedef vector<char>vch;
typedef vector<string>vs;
typedef map<int,int>mpii;
typedef map<int,bool>mpbi;
typedef map<long,bool>mpbl;
typedef map<long long,bool>mpbll;
typedef map<char,int>mpci;
typedef map<char,bool>mpbc;
typedef map<string,int>mpsi;
typedef map<long long,long long>mpll;
/// template
template<class T> T gcd(T a, T b ) {return b<=0?a:gcd(b,a%b);}
template<class T> T large(T a, T b ) {return a>b?a:b;}
template<class T> T small(T a, T b ) {return a<b?a:b;}
template<class T> T diffrnce(T a, T b) {return a-b<0?b-a:a-b;}
char H_D(LL num)
{
switch(num)
{
case 10:
return 'A';
break;
case 11:
return 'B';
break;
case 12:
return 'C';
break;
case 13:
return 'D';
break;
case 14:
return 'E';
break;
case 15:
return 'F';
break;
default:
break;
}
}
int D_H(char ch)
{
switch(ch)
{
case 'A':
return 10;
break;
case 'B':
return 11;
break;
case 'C':
return 12;
break;
case 'D':
return 13;
break;
case 'E':
return 14;
break;
case 'F':
return 15;
break;
default:
break;
}
}
int main()
{
string s;
vi v;
while(cin >> s)
{
if(s[0]=='-') break;
LL ans=0,i,p,len;
v.clear();
// hexa-decimal to decimal
if( (s[0]=='0' or s[0]=='O') and s[1]=='x')
{
ans = 0;
len = s.size();
for(i=2;i<len;i++)
{
if(isalpha(s[i]))
{
v.push_back(D_H(s[i]));
}
else
{
v.push_back(s[i]-48);
}
}
LL vlen=v.size();
p=vlen-1;
for(i=0;i<vlen;i++)
{
ans+=v[i]*powl(16,p);
p--;
}
pf("%lld\n",ans);
}
// decimal to hexa-decimal
else
{
ans=0;
len=s.size();
p=len-1;
for(i=0;i<len;i++)
{
ans+=(s[i]-48)*powl(10,p);
p--;
}
LL a=ans;
while(ans>0)
{
a=ans%16;
v.push_back(a);
ans/=16;
}
reverse(all(v));
LL vlen=v.size();
p=0,ans=0;
pf("0x");
for(i=0;i<vlen;i++)
{
if(v[i]<10)
{
pf("%d",v[i]);
}
else
{
pf("%c",H_D(v[i]));
}
}
nl;
}
}
return 0;
}
Comments
Post a Comment