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
#include<stdio.h>
int main()
{
int a,b;
int sum;
while(scanf("%d%d\n",&a,&b) != EOF){
sum = a+b;
if(sum < 0){
printf("-");
sum = -sum;
}
if(sum>=1000000){
printf("%d,%03d,%03d\n",sum/1000000, (sum/1000)%1000, sum%1000);
}
else if(sum >= 1000){
printf("%d,%03d\n",sum/1000,sum%1000);
} else{
printf("%d\n", sum);
}
}
return 0;
}
分享到:
相关推荐
目录1001 A+B Format (20分)思路一:不按他们的位数分情况处理代码一:用可变数组ArrayList+字符串截取方法subString代码二:栈Stack+字符串截取方法subString思路二:因为a和b的范围较小,所以可以按他们的位数分...
黑群晖最经典的版本 DSM_DS918+_24922.pat
Dy+VMware实现路由器端口映射的PAT配置实例.docDy+VMware实现路由器端口映射的PAT配置实例.doc
题目 题目链接 思路 把数字转化为字符串,倒序输出 大神的都是数字直接转为字符串,学到了 代码 第一个测试点不过,有会的可以帮我... a = a + b; if(a == 0) cout << 0; if(a<0) { a = -a; cout < 0){
DSM
PAT 1001. 害死人不偿命的(3n+1)猜想 C实现
servu是一款windows 服务器服务端ftp管理软件。servu配置很复杂,本篇内容详细介绍如何配置服务端...
CAD填充图案(三百多种)-.pat文件 部分如下(篇幅有限) 2x12木地板.pat 45度人字形砖面(1).pat 8x8无缝砖.pat Z形砖.pat 丁字砖面1.pat 丁字砖面2.pat 三联蜂窝.pat 三角形拼铺.pat 不能通行的沼泽地.pat 乱沙.pat...
DSM_DS918+_25426.pat,和synoboot.img是一个群晖的引导的镜像教程及来源https://post.smzdm.com/p/aqx07xmk/
PAT乙级1022源代码 codeblocks 输入两个非负10进制整数A和B(),输出A+B的D (1 )进制数。
DSM_DS220+_42962.pat
题意概述给定两个字符串 A 和 B,本题要求你输出 A+B,即两个字符串的并集。数据规模A 和 B 均为长度不超过${10}^6$的、由可见 ASCII 字符和
DSM_DS3622xs+_42951.pat
pat1.cpp
C语言编写-PAT乙级真题-1001.害死人不偿命-自己的思路,代码不是很规范,仅供参考
So I just add some logic to my .dcu files loader to generate .pat files in right format Supported Delphi versions: Delphi 2007 (v12) Delphi 2009 (v14) Delphi 2010 (v15) Delphi XE (v16) Delphi XE2 ...
我的PAT乙级练习题1001代码记录,题目地址:https://www.patest.cn/contests/pat-b-practise/1001
Neural Networks and Deep Learni - Pat Nakamoto.azw3
NAS群辉安装-DS918+_引导文件.img-DS918+_23824.pat