HDU 2051 Bitset

http://acm.hdu.edu.cn/showproblem.php?pid=2051

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 <bits/stdc++.h>

using namespace std;

char num[3]= {'0','1'};
char ans[1111]; int main()
{
int n;
while(~scanf("%d",&n))
{
int numm=0;
do
{
ans[numm++]=num[n%2];
n/=2;
}
while(n!=0);
for(int i=numm-1;i>=0;i--)
{
if(i!=0)
printf("%c",ans[i]);
else
printf("%c\n",ans[i]);
}
}
return 0;
}

  

上一篇:初识(试)LoadRunner


下一篇:[Oracle]审计Audit