杭电acm1015

来源:互联网 发布:飞机晚点查询软件 编辑:程序博客网 时间:2024/06/05 19:39

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
(1)大意:
  给出你一个十进制的数字,然后转化成二进制,输出。
(2)思路:
动态规划中,写一个简单的递归即可。每次n/2自后再作为参数递归下去,直到n/2不为真为止。
(3)感想:
略吧,找到规律,理解递归过程,实现就好了。
(4)
#include <iostream>using namespace std;void f(int n){ if (n / 2) {  f(n / 2); } cout << n % 2;}int main(){ int n; while (cin >> n) {  f(n);  cout << endl; } return 0;}
0 0
原创粉丝点击