hdu2051 Bitset
2016-12-01 12:29
176 查看
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
1
2
3
Sample Output
1
10
11
十进制转二进制,位操作实现
#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;
}
相关文章推荐
- HDU2051 Bitset
- HDU2051_Bitset
- hdu2051 Bitset(C语言)
- Bitset[HDU2051]
- hdu2051 bitset
- HDU2051 Bitset
- hdu2051 Bitset (十进制转化为二进制) java
- HDU2051 Bitset
- HDU2051 Bitset
- Hdu2051 *** Bitset (十进制化二进制)
- HDU2051 Bitset
- bitset对象或整型值的使用
- bitset 用法整理
- C++ Primer 学习笔记(2): bitset操作
- 标准库类型:string vector bitset
- Bitset
- 2051 Bitset
- bitset用法
- 使用java.util.BitSet 求素数的算法
- c++ 中 bitset 与 unsigned char 数组 转化,编译已通过