#include<iostream>
#include<stack>
using namespace std;
int main()
{
int num, temp;
stack<int> s;
bool neg;
while(cin >> num)
{
neg = (num >= 0)?false:true;
temp = neg?(-num):num;
while(temp > 0)
{
s.push(temp%2);
temp >>= 1;
}
cout.width(11); //以11位的宽度右对齐输出,只对接下来cout的第一个有效
cout << num << "-->" << (neg?"-":"");
if(num == 0) {cout << "0\n"; continue;}
while(!s.empty())
{
cout << s.top();
s.pop();
}
cout << endl;
}
return 0;
}
zjut1185 C++以n位宽度右对齐输出
最新推荐文章于 2023-01-11 21:44:05 发布