title describes converting a decimal non-negative integer up to 30 digits to a binary output. Input Description:
Multiple sets of data, each behaving as a decimal non-negative integer with a length not exceeding 30 bits.
(Note that the number of 10 binary digits may be 30, not a 30bits integer)
Output Description:
The binary number that corresponds to the output of each row.
Example 1
input
0
1
3
8
Output
0
1
1000
#include <iostream>
#include <string.h>
#include <cstring>
using namespace std;
int main () {
char str[32];
int Input[32],len;
int output[100];
while (~SCANF ("%s", &str)) {
len=strlen (str);
for (int i=0;i<len;i++) {
input[i] = str[i]-' 0 ';
}
memset (output,0,sizeof (output));
int sum = 1,d = 0, k = 0;
while (sum) {
sum = 0;
for (int i=0;i<len;i++) {
d = input[i]/2;
sum + = D;
if (i = = (len-1)) {
output[k++] = input[i]% 2;
}
else
input[i+1] + = (input[i]%2) *10;
Input[i] = D;
}
}
if (k = = 0)
cout<<0;
else{for
(int i=k-1;i>=0;i--)
cout<<output[i];
}
cout<<endl;
}
return 0;
}