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