HDOJ 2051

题目

Give you a number on base ten,you should output it on base two.(0 < n < 1000)

输入

For each case there is a postive number n on base ten, end of file.

输出

For each case output a number on base two

思路

辗转相除法做的 比较容易

代码

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	while(cin>>n)
	{
		int pos = 0;
		int bit[11] = {0};
		while(n)
		{
			bit[pos] = n%2;
			n/=2;
			pos++;
		}
		for(int i=pos-1;i>=0;i--)
			cout<<bit[i];
		cout<<endl;
	}
	return 0;
 } 
发布了63 篇原创文章 · 获赞 15 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/LieberVater/article/details/104532319
今日推荐