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)