PAT1001A+B Format (20)
来源:互联网 发布:绿盟数据库审计系统 编辑:程序博客网 时间:2024/06/05 02: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 9
Sample Output-999,991
int a = 1000000, b = 9; string num; a = a + b; stringstream ss; ss << abs(a); ss >> num; int len = num.length(); int t = 0; string str; for (int i = len-1; i >=0; --i){ if (t == 3){ str.push_back(','); t = 0; } ++t; str.push_back(num[i]); } len = str.length(); if (a < 0)cout << '-'; for (int i = len-1; i >= 0; --i){ cout << str[i]; }
0 0
- pat1001A+B Format (20)
- PAT1001A+B Format (20)
- A+B Format (20)
- A+B Format (20)
- A+B Format (20)
- 1001. A+B Format (20)
- 1001. A+B Format (20)
- PAT1001. 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)
- 上机报告5-1项目一数组分离
- 保存特殊字符到utf8编码的mysql数据库中
- 网络的可靠性
- Android 设置字体
- 堆排序
- PAT1001A+B Format (20)
- Android编程权威指南学习笔记02
- Manacher算法求字符串的最长回文子串
- 解决魅族手机在下拉刷新的时候出现hold
- 【NoSQL】redis集群的搭建
- C++STL中vector容器的用法
- 懒加载时,点语法使用注意事项
- centos6.5 安装和卸载R
- 观察者模式:使对象关注感兴趣的变化