Logop1143 hexadecimal conversion, logop1143 hexadecimal conversion

Source: Internet
Author: User

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

  

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.