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
一道看起来高端的水题。AC代码:
#include
#include
int main()
{
int two[1000], cache, len, i;
while (~scanf("%d", &cache))
{
memset(two, 0, sizeof(two));
i = 0;
while (cache !=0)
{
two[i] = cache % 2;
cache = cache / 2;
i++;
}
len = i;
for (i = (len-1); i >= 0; i--)
{
printf("%d", two[i]);
}
printf("n");
}
return 0;
}
一开始是直接用的strlen()函数,一直报错,郁闷……犯这种低级错误。( ̄﹏ ̄;)
最后也算欢乐的一次过了吧。(-。-;)
原文标题:HDOJ2051:Bitset|落絮飞雁的个人网站
授权协议:创作共用 署名-非商业性使用 2.5 中国大陆
除注明外,本站文章均为原创;转载时请保留上述链接。