DP 1015

来源:互联网 发布:android网络状态监听 编辑:程序博客网 时间:2024/05/24 06:55
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
110

11

简单题意:10进制转2进制

解题思路:模拟转化过程

感想:不知道怎么用DP……

AC代码:

#include<iostream>using namespace std;const int N = 100;int a[N];int main(){int n;while(cin >> n){int i = 1;if(!n) cout << 0  ;while(n != 0){if(!(n % 2)) {a[i] = 0;i ++ ;}else {a[i] = 1;i ++ ;}n = n / 2;}for(int j = i - 1;j != 0;j --)cout << a[j] ;cout << endl;}} 


0 0