cid=1079&pid=19">http://202.121.199.212/JudgeOnline/problem.php?cid=1079&pid=19

分析:主要是输出格式控制

  “对于每一个n,以11位的宽度右对齐输出n值”: 即包含该数在内一共11位,右对齐为printf的默认方式。所以用 %11d  来解决。

   另外,

         输出左对齐与右对齐,需在指定输出长度的时候才有意义; 如无指定长度,则输出从行首開始,有多长输出多长。

         左对齐: %-11d

  实例:

  

#include <stdio.h>

int main()
{
int a=123;
int b=1234;
int c=12345;
printf("%d\n%d\n%d\n",a,b,c); //没有规定输出长度
printf("\n%11d\n%11d\n%11d\n",a,b,c); //11位宽右对齐
printf("\n%-11d\n%-11d\n%-11d\n",a,b,c); //11位宽左对齐
return 0;
}

代码:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <iostream>
#include <string>
using namespace std; int main()
{
int n;
char buf[32];
while(scanf("%d",&n)!=EOF){
/* if(n>=0)
printf("%11d-->%s\n",n,itoa(n,buf,2));
else
printf("%11d-->-%s\n",n,itoa(-n,buf,2));
*/
printf("%11d-->",n);
if(!n) { printf("0\n"); continue;}
if(n<0) { n=-n; printf("-");}
string str="";
while(n){
str +=n%2 +'0';
n /=2;
}
for(int i=str.length()-1;i>=0;i--)
cout<<str[i];
cout<<endl;
}
return 0;
}

最新文章

  1. css的margin
  2. hibernate中validate的使用(转)
  3. asp.net identity 2.2.0 中角色启用和基本使用(三)
  4. ASP.NET MVC在布局页上使用模型(model)
  5. Java中“==”与equals方法的区别
  6. github上最全的资源教程-前端涉及的所有知识体系
  7. 浅谈jQuery页面的滚动位置scrollTop、scrollLeft
  8. DB2建立不记录日志的表
  9. 2D image convolution
  10. java输入输出高速
  11. 整理 W3CSchool 常用的CSS属性列表
  12. TI Davinci DM6446开发攻略——开发环境搭建
  13. passat product list
  14. ubantu中执行docker免sudo方法
  15. php+mysql 解决emoji问题
  16. DLL加载顺序
  17. hibernate ehcache二级缓存
  18. 如何恢复windows的exe文件的默认打开方式
  19. PHP学习 流程控制和数组
  20. m_Orchestrate learning system---三十五、php数据和js数据的解耦:php数据(php代码)不要放到js代码中

热门文章

  1. Ubuntu PPA 使用指南
  2. 原生的ajax请求----(播放托管到爱奇艺上的视频)
  3. 安装lnmp前请先运行screen
  4. 【BZOJ4176】Lucas的数论-杜教筛
  5. 在学校机房联想硬盘保护下安装Linux,并配置锐捷客户端
  6. hdoj Let the Balloon Rise
  7. CentOS-6.4-minimal版中源代码安装MySQL-5.5.38
  8. 关于Android制作.9.png图片
  9. QTP11.5公布,改名UFT
  10. [PHP]怎样在SAE的CodeIgniter项目中隐藏掉index.php