Basic practice hex-to-decimal time limit: 1.0s memory limit: 512.0MBThe problem description enters a positive hexadecimal number string that does not exceed 8 bits from the keyboard, converting it to a positive decimal number after the output.
Note: 10~15 in hexadecimal numbers are denoted by uppercase letters A, B, C, D, E, F, respectively. Sample input FFFF Sample output 65535 16-in-turn 10-step example: 8a5f=16^3*8+16^2*10+16^1*5+16^0*15;
#include <stdio.h> #include <string.h> #include <string> #include <math.h> #include < Algorithm> #define LL Long long#define PI atan (1.0) *4#define DD doublea#define MAX 100100#define mod 10007using Namespac e Std;char a[10]; Char s[]= "ABCDEF"; int main () { int n,m,j,i,len,sum; while (scanf ("%s", a)!=eof) { int len=strlen (a); LL sum=0; Strrev (a); for (i=0;i<len;i++) { if (a[i]>= ' 0 ' &&a[i]<= ' 9 ') sum+= (POW (16,i) * (a[i]-' 0 ')); else if (a[i]>= ' a ' &&a[i]<= ' F ') {for (j=0;j<6;j++) { if (A[i]==s[j]) { sum+= (POW (16,i) * (j+10)); Break ; }}}} printf ("%lld\n", sum);
Blue Bridge Cup Basics practice hex to Decimal