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