您的位置:首页 > 编程语言 > C语言/C++

进制转换问题(c++)

2017-03-07 20:43 288 查看
建立顺序栈或链栈,编写程序实现十进制数到二进制数的转换。
Description
输入只有一行,就是十进制整数。
Input

转换后的二进制数。
Output

1

10

Sample Input

1

1010

#include<iostream>
#include<string>
#include<cstdlib>
#include<list>
#include<stack>
using namespace std;

int main()
{
int n;
while (cin >> n)
{
stack<int> z;
while (n != 0)
{
z.push(n% 2);
n = n / 2;
}
while (!z.empty())
{
cout << z.top();
z.pop();
}
cout << '\n';
}
return 0;
}


//by swust_t_p
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: