HDUOJ2051:Bitset

版权声明:qq836678589 https://blog.csdn.net/weixin_43924623/article/details/90901609

Bitset

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

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>
using namespace std;
int main(){
	int n,i,a,b[100];
	while(cin>>n){
		int j=0;
		while(n!=0){
			a=n%2;
			n=n/2;
			b[j]=a;
			j++;
		}
		for(int k=j-1;k>=0;k--){
			cout<<b[k];
		}
		cout<<endl;
}
	return 0;
}

**总结:**转换成二进制,囤入数组中,然后反转,注意不要越界。

猜你喜欢

转载自blog.csdn.net/weixin_43924623/article/details/90901609
今日推荐