Logop2084 hexadecimal conversion, logop2084 hexadecimal conversion

Source: Internet
Author: User

Logop2084 hexadecimal conversion, logop2084 hexadecimal conversion
Background

None

Description

Today, James learned the hexadecimal conversion, such as (10101) 2. Then its decimal expression is:

1*2 ^ 4 + 0*2 ^ 3 + 1*2 ^ 2 + 0*2 ^ 1 + 1*2 ^ 0,

Then you can program the implementation to convert a M-in-number N into a decimal expression.

Note: When the coefficient is 0, this monominal is omitted.

Input/Output Format

Input Format:

 

Two numbers, M and N, separated by spaces in the middle.

 

Output Format:

 

A total of rows in decimal format.

 

Input and Output sample input sample #1: Copy
2 10101
Output example #1: Copy
1*2^4+1*2^2+1*2^0
Description

For 100% of data, the number of digits of 1 <M <10, N cannot exceed 1000.

 

 

The teacher zhx said that the noip should be used for additional questions 23333 in the early stage.

The question is very simple. Find the rule. For a number not 0, output it.

 

#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;const int MAXN=1e6+10;inline int read(){char c=getchar();int f=1,x=0;while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-48,c=getchar();return x*f;}int n;char s[MAXN];bool flag=0;int main(){n=read();scanf("%s",s+1);int ls=strlen(s+1);for(int i=1;i<=ls;i++){if(s[i]!='0'){if(flag==0)printf("%d*%d^%d",s[i]-48,n,ls-i),flag=1;elseprintf("+%d*%d^%d",s[i]-48,n,ls-i);}}return 0;}

  

 

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.