Total Submission(s): 23901 Accepted Submission(s): 17756
Problem Description
Give you a number on base ten,you should output it on base two.(0 < n < 1000)
Input
For each case there is a postive number n on base ten, end of file.
Output
For each case output a number on base two.
Sample Input
1 2 3
Sample Output
1 10 11
题目简单,代码如下:
#include<iostream>
using namespace std;
void sol(int n) {
if(n) sol(n>>1),cout << n%2;//利用n>>1等于n/2 ,n<<1等于n*2
else return ;
}
int main() {
int n;
while(cin >> n) {
sol(n);
cout<< endl;
}
return 0;
}