Hdoj 2051 Bitset
2018-01-13 15:43
204 查看
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
校庆杯Warm Up
题目分析
将一位10进制数转换为2进制数,用位操作实现,每次取出二进制时的最后一位,然后放到数组里面,再用>>去掉二进制的最后一位,注意输出的时候的顺序是反过来的
Code
更多问题请关注个人博客,不定时更新
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
校庆杯Warm Up
题目分析
将一位10进制数转换为2进制数,用位操作实现,每次取出二进制时的最后一位,然后放到数组里面,再用>>去掉二进制的最后一位,注意输出的时候的顺序是反过来的
Code
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cctype> #include<cstring> #include<cstdlib> using namespace std; typedef __int64 ll; int len; int a[70]; int transbit(int n) { memset(a,0,sizeof(a)); int num=0; while(n>0) { if(n&1) a[++num]=1; else a[++num]=0; n>>=1; } return num; } int main() { int n; while(cin>>n) { int len = transbit(n); for(int i=len;i>=1;i--) { cout<<a[i]; } cout<<endl; } return 0 ; }
更多问题请关注个人博客,不定时更新
相关文章推荐
- hdoj.2051 Bitset 20140729
- HDOJ 2051 Bitset
- HDOJ2051_Bitset
- HDOJ 2051 Bitset
- hdoj-2051-Bitset
- Hdoj 2051 Bitset
- HDOJ-- 2051 Bitset
- Bitset hdoj 2051
- hdoj 2051 Bitset(数的进制转换问题)
- hdoj 2051 Bitset【10进制转2进制】
- hdoj-2051-Bitset
- hdoj 2051 Bitset (进制转换)
- Bitset hdoj 2051
- hdoj 2051 Bitset
- HDOJ 2051 Bitset
- [HDOJ5890]Eighty seven(暴力,dp,bitset)
- hdoj:2051
- HDU 2051 - Bitset
- HUD 2051 Bitset (水)
- hdu 2051 Bitset 把一个十进制转化为2进制数