Huawei computer questions

Source: Internet
Author: User

Parse the 9-in-9 format. The 11-in-11 string is a 10-in-10 numeric output. The length of the input string's valid bits (0v0012345678) is no more than 8 bits. The previous 00 is not a valid bits. After resolution, it is output in decimal format.
-1 is returned if an invalid string is parsed.

9 hexadecimal:
The value range of the 9-digit number is 0, 1, 2, 3, 4, 5, 6, 7, and 8.
9: 0 V or 0 V
Example of a 9-digit system: 0v11 0v564 0v123 0v0784 0v0 0 V 0 V
9-digit error instance: 0v923 0vt12 00v21 0123
9-to-10: 0v11-> 10
0v564-> 463
 
11 hexadecimal:
The range of numbers in the 11 hexadecimal format: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A ()
The start of the 11 hexadecimal format is 0 w or 0 w.
Correct 11-digit example: 0w11 0w564 0w123 0w0a8a 0 w 0 w
11 hexadecimal error instance: 0wb923 0 wvaa 00w21 0wax123
Convert the hexadecimal value to the hexadecimal value:
0w11-> 12
0w564-> 675

 

 

#include <math.h>#include<iostream>#include <string>using namespace std;void main(){        string str;    cin>>str;    int len=str.length();        char *ch=new char[len];    for (int i=0;i<len;i++)    {        ch[i]=str[i];    }    int iRet=0;    if (ch[0]==‘0‘&&(ch[1]==‘v‘||ch[1]==‘V‘))    {        for (int i=len-1;i>1;i--)        {            if (ch[i]>‘8‘||ch[i]<‘0‘)            {                cout<<-1;                return;            }            iRet+=(ch[i]-‘0‘)*((int)pow(9.0,len-1-i));        }    }    else if (ch[0]==‘0‘&&(ch[1]==‘w‘||ch[1]==‘W‘))    {        for (int i=len-1;i>1;i--)        {            if (ch[i]!=‘a‘&&ch[i]!=‘A‘&&(ch[i]>‘9‘||ch[i]<‘0‘))            {                cout<<-1;                return;            }            if (ch[i]==‘a‘||ch[i]==‘A‘)            {                ch[i]=‘0‘+10;            }            iRet+=(ch[i]-‘0‘)*((int)pow(11.0,len-1-i));        }    }    else         {             cout<<-1;              return;         }    cout<<iRet;    }

 

Related Article

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.