Foreword alas, I always feel that I can only do my best to help my teachers. In the past year, students are still reliable, and their educational qualifications are highly reliable, so they cannot reflect all problems, but it can reflect most of the problems. At least I am a master's who often learns algorithms or other computer things late at night. Question [html] Description: converts a decimal non-negative integer with a maximum length of 30 digits into a binary number. Input: multiple groups of data. Each row contains a decimal non-negative integer of no more than 30 digits. (Note that there may be 30 decimal numbers, rather than an integer of 30bits) Output: the binary number corresponding to each row. Sample input: 0 1 3 8 sample output: 0 1 11 1000 the idea is obvious. A 30-bit integer cannot be expressed in the long int type, therefore, we use the data structure of char str [30] to store the big integer represented by this big integer string and convert it to another hexadecimal number step www.2cto.com. By adding each digit of the divisor, we can determine whether the value is greater 0 is used as the termination condition of the outer loop. The inner layer is divided by bits, it is stored in an array of characters. Assume that after the outer loop of str2 ends, the str2 array needs to be in reverse order (the principle is equivalent to using the stack data structure for hexadecimal conversion) the process of derivation on the calculation paper (0: 10 still learning Code cannot afford to hurt): AC code [cpp] # include <stdio. h> # include <string. h> # include <stdlib. h> # define DATA 40 # define MAX 200 void tenToBin (char * str); char bin [MAX]; int Main () {char str [DATA]; while (scanf ("% s", str )! = EOF) {tenToBin (str); puts (bin);} return 0;}/*** Description: converts a string integer to a binary string */void tenToBin (char * str) {int I, j, k, len, sum, d; char temp; // initialization parameter sum = 1; len = strlen (str); k = 0; memset (bin, 0, sizeof (bin); while (sum) {sum = 0; for (I = 0; I <len; I ++) {d = (str [I]-'0')/2; sum + = d; if (I = len-1) {bin [k ++] = (str [I]-'0') % 2 + '0 ';} else {str [I + 1] + = (str [I]-'0') % 2*10;} str [I] = d + '0 ';}} // reverse order for (I = 0, j = k-1; I <j; I ++, j --) {temp = bin [j]; bin [j] = bin [I]; bin [I] = temp ;}} /*************************************** * *********************** Problem: 1138 User: wangzhengyi Language: C Result: Accepted Time: 90 MS Memory: 908 kb ************************************** **************************/