NOJ 1012 hexadecimal conversion (decimal to any hexadecimal), noj1012

Source: Internet
Author: User

NOJ 1012 hexadecimal conversion (decimal to any hexadecimal), noj1012

Question:

Hexadecimal conversionTime limit (Common/Java):1000 MS/3000 MS running memory limit: 65536 KByte
Total submissions: 1819 pass the test: 525

Description

Converts a decimal number N to an R-base number output, 2 ≤ R ≤ 16, R = 10.



Input

Multiple rows. The first line indicates the total number of groups of data in the following table. Each subsequent row contains two integers, N and R, separated by spaces.-100000 ≤ N ≤ 100000,2 ≤ R ≤ 16, R = 10.

Output

Multiple rows. Each row provides the converted R base number.

Sample Input

3
7 2
23 12
-4 3

Sample output

111
1B
-11

Prompt

 

Question Source

GUOJ



Question Analysis:

Simple question. Use itoa to convert decimal to any base ..



The Code is as follows:

/**. Cpp ** Created on: March 31, 2015 * Author: Administrator */# include <iostream> # include <cstdio> # include <cstdlib> using namespace std; const int maxn = 32; char numbers [maxn]; void toUpper (char str []) {int I = 0; while (str [I]! = '\ 0') {if (str [I]> = 'A' & str [I] <= 'Z') {str [I]-= 32 ;} I ++ ;}} int main () {int t; scanf ("% d", & t); while (t --) {int n; int base; scanf ("% d", & n, & base); bool flag = false; if (n <0) {n =-n; flag = true ;} itoa (n, numbers, base); toUpper (numbers); if (flag = true) {printf ("-");} printf ("% s \ n ", numbers);} 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.