2 Conversion to 3 system
Describes the input of a 2-digit number, which requires an output of the 16-binary representation of the 2-binary number.
In the 16 binary representation, A-f represents 10-15
Enter Line 1th is the number of group N of the test data, followed by the n row input. Each set of test data takes up to 1 rows, including a string of 0 and 1, with a string length of at least 1, at most 10000 output n rows, and one input per line output. Sample input
2
100000
111
Sample output
7
problem link : Bailian3709 2 into 3 into the system
A brief introduction to the problem: 2 to 16 into the system, each 4-bit into 1-bit.
Problem Analysis :
The number of digits in the 2 number is unknown in advance, in order to add 4 ' 0 ' to the front of the 2-digit number to facilitate conversion.
The result of the transformation is placed in the same array, and the appropriate array subscript calculation is required.
The 16 binary value is converted to a 16 character and is implemented using the Look-up table (which can also be implemented in program logic), using the array convert[].
Program Description : (slightly)
Preface : (slightly)
The C language program for AC is as follows:
/* Bailian2798 2 into 16/
#include <stdio.h>
#include <string.h>
#define N 10000
# Define N2 4
char s[n + N2 + 1];
Char convert[] = "0123456789ABCDEF";
int main (void)
{
int n, len, digits, I, K;
scanf ("%d", &n);
GetChar ();
while (n--) {
gets (s + N2);
S[0] = s[1] = s[2] = s[3] = ' 0 ';
Len = strlen (s + N2); * * 2 Number of digits *
/digits = (len + n2-1)/N2; * * 16 digits
/len + + n2-1;
For (I=1, K=len, i<=digits; i++) {
s[k--] = convert[(s[len-3]-' 0 ') * 8 + (S[len-2]-' 0 ') * 4 + (s[len-1)- ' 0 ') * 2 + (S[len]-' 0 ')];
Len-= N2;
}
printf ("%s\n", &s[k + 1]);
return 0;
}