C++ 递归,移位Bitset

来源:互联网 发布:经典c语言程序小游戏 编辑:程序博客网 时间:2024/06/05 05:18


Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
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
123
 

Sample Output
11011

 题目简单,代码如下:
#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; }