1001. A+B Format (20)
来源:互联网 发布:网络购彩平台贴吧 编辑:程序博客网 时间:2024/06/03 04:19
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 9Sample Output
-999,991
#include<iostream>
#include<math.h>
using namespace std;
int main (){
int a,b,sum,i,j,k;
cin>>a>>b;
sum=a+b;
i=sum/1000000;
j=(sum%1000000)/1000;
k=(sum%1000);
if(abs(sum)<1000){
cout<<k<<endl;
}
if(abs(sum)>999&&abs(sum)<1000000){
printf("%d,%03d\n",j,abs(k));
}
if(abs(sum)>999999){
printf("%d,%03d,%03d\n",i,abs(j),abs(k));
}
return 0;
}
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- HashMap源码解析
- 深入理解ES6--块级作用域(let const)
- 希尔排序
- redis 持久化的两种方式
- 事务笔记
- 1001. A+B Format (20)
- GitHub 博客自定义域名配置(阿里)
- 4岁开始升牛,9岁死----分支简单算法
- Java线程状态
- [华为刷题]分解字符串,string解法
- 在 Xshell 中 使用 hbase shell 进入后 无法删除
- 几何图形的绘制
- HDU
- 【数据结构】最大子序列问题