hdu2051 Bitset

来源:互联网 发布:淘宝上可以卖膏药吗 编辑:程序博客网 时间:2024/05/21 10:14

Bitset

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 21497    Accepted Submission(s): 15952


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>#include<cstdio>using namespace std;int main(){int n;while(cin>>n){int cur=1<<10;while(!(cur&n))cur>>=1;//忽略无效的0 while(cur)//从第一个非0的位开始一位一位输出 {printf("%d",!!(cur&n));//打印每一位的值 cur>>=1;}printf("\n");}return 0; } 



0 0
原创粉丝点击