Z - Bitset
题目描述
Give you a number on base ten,you should output it on base two.(0 < n < 1000)
Iutput
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 <cstdio>
#include <stack>
using namespace std;
int main()
{
stack<int> st;
int x;
while(scanf("%d",&x)!=EOF)
{
int temp;
while(x)
{
temp=x%2;
st.push(temp);
x=x/2;
}
while(!st.empty())
{
temp=st.top();
st.pop();
printf("%d",temp);
}
printf("\n");
}
return 0;
}