Noj 1012 binary conversion (decimal conversion to any binary)

Source: Internet
Author: User

Topic:

Binary Conversion time limit (normal/java) : ms/3000 MS Run memory limit: 65536 KByte
Total Submissions: 1819 tested by: 525

Title Description

Converts a decimal number n to the output of the R-binary number, 2≤r≤16,r≠10.



Input

MultiRow The first line indicates how many sets of data are in the following line, each followed by two integers N and R, separated by a space, -100000≤n≤100000,2≤r≤16,r≠10.

Output

MultiRow Each row gives the converted R binary number.

Sample input

3
7 2
23 12
-4 3

Sample output

111
1 b
-11

Tips

Source of the topic

Guoj



Topic Analysis:

Simple question. Convert decimal to any binary using Itoa.



The code is as follows:

/* * a.cpp * *  Created on:2015 March 31 *      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]! = ' + ') {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%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;}





Noj 1012 binary conversion (decimal to any binary)

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.