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;}