1075 numeric Conversion

Source: Internet
Author: User

Description

The structure of a $ string is: a $ ='m (n) P', where M is a string (length <= 20), and N, P is a string of 1 or 2 digits (the content expressed in the string is between 2 and 10 ).ProgramRequirement: after reading a $ from the keyboard (correctness check is not required), output the numeric string M (N hexadecimal) in a $ in the form of P. For example, a $ = '48 (10) 8' indicates converting a 10-digit number 48 to an 8-digit number output. Output result: 48 (10) = 60 (8)
Input

Contains multiple groups of test data. A string is separated by one (n) in the middle. Before (N), it is an integer m. N indicates N in hexadecimal notation. After (N), it is an integer p, converts n to a P-based string to occupy a row.
Output

Each output occupies a row and outputs M (n) = Q (p) in the following format, indicating that m in the n-base and Q in the p-base are equal.
Sample input 48 (10) 8 sample output

48 (10) = 60 (8)

Solution:
First extract each digit and then restore it in hexadecimal format. The result is in decimal format. Next, extract the bit according to the new paper feed.

 

# Include <stdio. h> # include <math. h> main () {long m; int N, P; long result; int A [200]; int up; int I; long T; long xx; while (scanf ("% LLD (% d) % d", & M, & N, & P )! = EOF) {T = m; up = 0; // printf ("% d \ n", m); While (M! = 0) {A [Up] = m % 10; up ++; M = m/10; // printf ("% d \ n ", A [Up-1]);} result = 0; xx = 1; for (I = 0; I <up; I ++) {result = Result + XX * A [I]; xx = XX * n;} // printf ("% LLD \ n", result ); // printf ("% d \ n", P); up = 0; while (result! = 0) {A [Up] = Result % P; up ++; Result = Result/P;} result = 0; xx = 1; for (I = 0; I <up; I ++) {result = Result + XX * A [I]; xx = XX * 10;} printf ("% LLD (% d) = % LLD (% d) \ n ", t, n, result, p );}}

 

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.