cpptemplate.cpp
来自「十进制转换为二进制的3种实现方法」· C++ 代码 · 共 40 行
CPP
40 行
//=====================================
// title: 十进制转化为二进制
// author: cjj
// date: 2007-10-09
/* Description:
*/
//=====================================
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
for(int n; cin>>n;)
{
if(n==0)
{
cout<<setw(11)<<right<<"0-->0\n";
continue;
}
string s;
for(int a=n; a;)
{
s+=(a%2?'1':'0');
a/=2;
}
reverse(s.begin(), s.end());
cout<<setw(11)<<right<<n<<"-->"<<(n<0?"-":"")<<s<<endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?