1015 Problem O

来源:互联网 发布:淘宝京剧服装 编辑:程序博客网 时间:2024/06/05 15:21

1015 Problem O

    题意:Give you a number on base ten,you shouldoutput it on base two.

思路:十进制转二进制,用该数不断除以2,能整除则记录0,不能则记为1,这里在输出时需要倒序输出。

#include<iostream>

using namespace std;

int main(){

   int n,i,m;

   long long f[100000];

   while(scanf("%d",&n)!=EOF){

       i=0;

       do{

           i++;

           if(n%2==0)

           {

                f[i]=0;

                f[i+1]=n/2;

           }

           else  f[i]=1;

           n=n/2;

       }while(n>0);

       for(m=i;m>0;m--)

           cout<<f[m];

       cout<<endl;

    }

   return 0;

}

0 0
原创粉丝点击