1001. A+B Format (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).

Input

Each input file contains one test case. Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.

Output

For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.

Sample Input

-1000000 9

Sample Output

-999,991

解题思路:这里主要是注意一下补0的问题

     %nd:n代表的是列宽长度。

(1)%-nd   -  代表的是左对齐。

(2)%nd       代表的是右对齐。

(3)%0nd   0(数字零)代表的是不足n位长度的左补齐0。

 #include<stdio.h>
#include<stdlib.h> int main()
{
int a,b;
int sum = ;
scanf("%d %d",&a,&b); sum = a+b;
if( sum<){
printf("-");
sum = -sum;
}
if( sum>=){
printf("%d,%03d,%03d",(sum/),(sum/%),(sum%));
}
else if( sum>=){
printf("%d,%03d",(sum/),(sum%));
}
else printf("%d",sum);
return ;
}

最新文章

  1. PHP导入导出excel表格图片(转)
  2. PHP数组及简单函数
  3. 分布式搜索引擎ElasticSearch+Kibana (Marvel插件安装详解)
  4. mybatis-generator-config工具的使用
  5. Git 配置
  6. bonext.js学习笔记
  7. liunx系统计划任务管理(at/crond调度)
  8. smarty模板原理
  9. codevs 2924 数独
  10. hdu 2029
  11. Arraylist和Vector的区别与HashMap和Hashtable的区别
  12. 想成为真正的代码gg,目标
  13. MyEclipse 8.5配置Tomcat7.0
  14. git源码中的Makefile
  15. firefox浏览器删除插件
  16. RobotFramework+Selenium2library+Appium+Python+RIDE安装指南
  17. Java面向对象 其他对象
  18. 12月4日学习爬虫007.使用Urllib模块进行简单网页爬取
  19. 英语考试 FZU - 2254 (最小生成树)
  20. 使用react 在页面上引用静态图片,图片不显示

热门文章

  1. 453 Minimum Moves to Equal Array Elements 最小移动次数使数组元素相等
  2. 417 Pacific Atlantic Water Flow 太平洋大西洋水流
  3. 017:COM1无法打开
  4. 奇葩问题: lsattr -d /data 显示:----------I--e- /data/
  5. JS操作CSS
  6. poj3662 Telephone Lines
  7. joomla建站-双语CMS系统开发的实现
  8. Elasticsearch--集群&amp;时光之门和恢复控制
  9. 微信小程序组件解读和分析:十四、slider滑动选择器
  10. APP崩溃处理