01: Numeric conversion, 01 numeric Conversion

Source: Internet
Author: User

01: Numeric conversion, 01 numeric Conversion
01: Numeric Conversion

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

Returns the conversion of any two non-negative integers of different hexadecimal notation (decimal order ~ Hexadecimal), the given integer is within the range that long can express.
Different hexadecimal notation is ,..., 9, a, B ,..., f) or (0, 1 ,..., 9, A, B ,..., F ).

Input
The input contains only one row, which contains three integers a, n, and B. A indicates that the n after it is an a-hexadecimal integer, and B indicates that you want to convert a-hexadecimal integer n to a-hexadecimal integer.
A and B are decimal integers, 2 = <a, B <= 16.
Output
The output contains a row. This row has an integer that is the converted hexadecimal number. Uppercase letters are all used for output, that is, (0, 1,..., 9, A, B,..., F ).
Sample Input
15 Aab3 7
Sample output
210306
Source
2005 ~ 2006 Final Examination of Introduction to computing in the Medical Department
1 # include <iostream> 2 # include <cstdio> 3 # include <cmath> 4 # include <cstring> 5 using namespace std; 6 char a [10001]; 7 int B [10001]; 8 int now; 9 int tot; 10 int n; // unconverted hexadecimal 11 int m; // The hexadecimal 12 int da [10001]; 13 char w [20] = {'A', 'B', 'C', 'D ', 'E', 'F'}; 14 int main () 15 {16 cin> n; 17 scanf ("% s", & ); 18 19 cin> m; 20 int l = strlen (a); 21 if (a [0] = '0' & l = 1) 22 {23 cout <"0"; 24 return 0; 25} 26 for (int I = 0; I <l; I ++) 27 {28 if (a [I]> = 97 & a [I] <= 122) 29 {30 a [I] = a [I]-32; 31} 32 if (a [I]> = 49 & a [I] <= 57) 33 {34 B [I] = a [I]-48; 35} 36 else if (a [I]> = 65 & a [I] <= 90) 37 {38 B [I] = a [I]-55; 39} 40} 41 int ans = 0; 42 int now = 0; 43 for (int I = L-1; i> = 0; I --) 44 {45 ans = ans + B [I] * (pow (n, now); 46 now ++; 47} 48 int now2 = 1; 49 while (ans! = 0) 50 {51 int r = ans % m; 52 B [now2] = r; 53 ans = ans/m; 54 now2 ++; 55} 56 for (int I = now2-1; I> = 1; I --) 57 {58 if (B [I] <10) 59 cout <B [I]; 60 else 61 {62 int k = B [I]-10; 63 cout <w [k]; 64} 65} 66/* for (int I = now2; i> = 0; I --) 67 cout <da [I]; */68 return 0; 69}

Note that a is 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.