Logop1143 hexadecimal conversion, logop1143 hexadecimal conversion
Description
Compile a program to convert data between two different hexadecimal formats.
Input/Output Format
Input Format:
There are three input rows. The first row is a positive integer, which indicates the hexadecimal n (2 ≤ n ≤ 16) of the number to be converted, and the second row is an hexadecimal number, if n> 10, uppercase letters A ~ are used ~ F indicates digital 10 ~ 15. The decimal value corresponding to the n-base number cannot exceed 1000000000. The third row is also a positive integer, indicating the hexadecimal m (2 ≤ m ≤ 16) of the converted number ).
Output Format:
The output contains only one row and a positive integer, indicating the number of m-base after conversion.
Input and Output sample input sample #1: Copy
16FF2
Output example #1: Copy
11111111
First, convert a number to decimal.
Use the multiplication accumulation method during conversion
Then convert to m-base.
Continuous modulo (xjb) during conversion: joy:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#define LL long long using namespace std;const int MAXN=1e6+10;const int mod=1e9+7;inline int read(){char c=getchar();int flag=1,x=0;while(c<'0'||c>'9'){if(c=='-')flag=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-48,c=getchar();return x*flag;}int n,m;char s[MAXN];int a[MAXN],b[MAXN],tot=-1,ans=0,now=1;int out[MAXN],cnt=0;int main(){for(int i='0';i<='9';i++)a[i]=++tot,b[tot]=i;for(int i='A';i<='Z';i++)a[i]=++tot,b[tot]=i;n=read();scanf("%s",s+1);m=read();int ls=strlen(s+1);for(int i=ls;i>=1;i--)ans+=a[ s[i] ]*now,now=now*n;now=0;while(ans)out[++cnt]=ans%m,ans/=m;for(int i=cnt;i>=1;i--)printf("%c",b[ out[i] ]);return 0;}