您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  hdu 水题 bitset