【题目】
【思路】使用栈实现十进制到二进制的转换即可。
【代码】AC的C++代码如下:
#include <iostream>
#include <stack>
using namespace std;
void changeToTwo(int n)
{
stack<int> s;
while (n != 0)
{
s.push(n % 2);
n = n / 2;
}
while (!s.empty())
{
cout << s.top();
s.pop();
}
cout << endl;
}
int main()
{
int n;
while (cin >> n)
{
changeToTwo(n);
}
return 0;
}