1001. A+B Format (20)
来源:互联网 发布:lol30级号淘宝 编辑:程序博客网 时间:2024/05/28 06:05
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<iomanip>using namespace std;int main(){int a, b,sum;int first=0, second=0;cin >> a >> b;sum = a + b;first = sum % 1000;if (sum/1000==0)cout << first << endl;else{second = (sum / 1000) % 1000;if ((sum / 1000) /1000 == 0)cout << second << "," << setw(3)<<setfill('0')<<abs(first) << endl;elsecout << sum/1000000 << "," << setw(3)<<setfill('0')<<abs((sum / 1000) - (sum/1000000) * 1000) << "," <<setw(3)<<setfill('0')<< abs(first) << endl;}return 0;}
0 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)
- android开发常用代码(经常更新)
- mysql 5.6 status 分类
- UBUNTU 12.04下编译安装 GCC4.1.2
- CRC从原理到实现
- 2.3.1 向索引添加文档例程
- 1001. A+B Format (20)
- apache启用gzip压缩方法
- ArcEngine数据编辑操作--通过线创建面
- Managing Your App's Memory(Android App内存管理)
- RabbitMq 消息队列的安装、使用 、原理
- Matlab基本函数
- jquery实现浏览器滚动加载
- Lua脚本编程:Lua语言入门
- JSONObject以及json(转)