码迷,mamicode.com
首页 > 其他好文 > 详细

HDoj 2051 Bitset

时间:2020-04-10 00:29:53      阅读:80      评论:0      收藏:0      [点我收藏+]

标签:number   for   ali   sample   problems   NPU   style   eof   scan   

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
 

 

Author
8600 && xhd
 

 

Source
 

 

 

 

Recommend
linle   |   We have carefully selected several similar problems for you:  2055 2052 2053 2054 2071 
 
 
 
 
C语言代码如下:
#include<stdio.h>
int main()
{
    int n=0;
    int l=0;
    char s[20];
    while(scanf("%d",&n)!=EOF)
    {
        l=0;
        while(n!=0)
        {
            s[l++]=n%2;
            n/=2;
        }
        for(int i=l-1;i>=0;i--)
            printf("%d",s[i]);
        printf("\n");
    }
}

 

 

HDoj 2051 Bitset

标签:number   for   ali   sample   problems   NPU   style   eof   scan   

原文地址:https://www.cnblogs.com/wzmm/p/12670467.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!