Blue Bridge Cup Basics practice hex to Decimal

Source: Internet
Author: User
Tags hex to decimal

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.