#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
long long int len,arr[100],i,j,k,l,m,n,a,b,c,sum;
char str[100];
while(scanf("%s",&str)==1)
{
if(str[0]=='-')
{
break;
}
len=strlen(str);
k=0;
if(str[k]=='0'&&str[k+1]=='x')
{
j=0;
for(i=2; i<len; i++)
{
if(str[i]>='0'&&str[i]<='9')
{
arr[j++]=str[i]-48;
}
else if((str[i]>='A'&&str[i]<='F')||(str[i]>='a'&&str[i]<='f'))
{
if(str[i]=='A'||str[i]=='a')
{
arr[j++]=10;
}
else if(str[i]=='B'||str[i]=='b')
{
arr[j++]=11;
}
else if(str[i]=='C'||str[i]=='c')
{
arr[j++]=12;
}
else if(str[i]=='D'||str[i]=='d')
{
arr[j++]=13;
}
else if(str[i]=='E'||str[i]=='e')
{
arr[j++]=14;
}
else if(str[i]=='F'||str[i]=='f')
{
arr[j++]=15;
}
}
}
a=0;
sum=0;
for(l=j-1;l>=0;l--)
{
sum=sum+(arr[l]*pow(16,a));
a++;
}
printf("%lld\n",sum);
}
else
{
b=0;
for(m=0;m<len;m++)
{
c=b*10+str[m]-48;
b=c;
}
printf("0x%X\n",b);
}
}
return 0;
}
#include<math.h>
#include<string.h>
int main()
{
long long int len,arr[100],i,j,k,l,m,n,a,b,c,sum;
char str[100];
while(scanf("%s",&str)==1)
{
if(str[0]=='-')
{
break;
}
len=strlen(str);
k=0;
if(str[k]=='0'&&str[k+1]=='x')
{
j=0;
for(i=2; i<len; i++)
{
if(str[i]>='0'&&str[i]<='9')
{
arr[j++]=str[i]-48;
}
else if((str[i]>='A'&&str[i]<='F')||(str[i]>='a'&&str[i]<='f'))
{
if(str[i]=='A'||str[i]=='a')
{
arr[j++]=10;
}
else if(str[i]=='B'||str[i]=='b')
{
arr[j++]=11;
}
else if(str[i]=='C'||str[i]=='c')
{
arr[j++]=12;
}
else if(str[i]=='D'||str[i]=='d')
{
arr[j++]=13;
}
else if(str[i]=='E'||str[i]=='e')
{
arr[j++]=14;
}
else if(str[i]=='F'||str[i]=='f')
{
arr[j++]=15;
}
}
}
a=0;
sum=0;
for(l=j-1;l>=0;l--)
{
sum=sum+(arr[l]*pow(16,a));
a++;
}
printf("%lld\n",sum);
}
else
{
b=0;
for(m=0;m<len;m++)
{
c=b*10+str[m]-48;
b=c;
}
printf("0x%X\n",b);
}
}
return 0;
}
0 comments: (+add yours?)
Post a Comment