PAT甲级1001
来源:互联网 发布:post请求返回json数据 编辑:程序博客网 时间:2024/06/05 17:15
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 9Sample Output
-999,991
#include<stdio.h>#include<iostream>#include<string>#include<map>#include<vector>#include<set>#include<algorithm>using namespace std;void process(int a){vector<int> v;int temp;do{temp = a % 10;a /= 10;v.push_back(temp);} while (a);for (int i = 0; i < v.size(); i++){cout << v[v.size() - 1 - i];if ((v.size() - 1 - i) % 3 == 0 && i != v.size() - 1)cout << ',';}}int main(){int a, b;cin >> a >> b;int sum = a + b; bool flag = false;if (sum < 0){sum = -sum;flag = true;}if (flag)cout << '-';process(sum);return 0;}
0 0
- PAT甲级1001
- PAT甲级1001
- PAT甲级习题(1001)
- PAT-甲级-1001
- PAT甲级1001
- PAT甲级1001,1002
- PAT甲级1001题解
- PAT甲级1001
- PAT甲级1001
- 浙大PAT甲级-1001
- PAT甲级 1001
- PAT 甲级 1001
- PAT甲级1001-1004
- PAT 甲级 1001
- PAT 甲级练习 1001
- pat甲级1001
- PAT 甲级
- PAT甲级1001-Public Bike Management (30)
- 使用tinyXML2 读写配置文件
- 深入理解C#:编程技巧总结(二)
- 二分图匹配模板
- 最常用的Eclipse快捷键
- 程序员面试金典: 9.9 递归和动态规划 9.9八皇后问题
- PAT甲级1001
- Ubantu 14.04 下连接mysql
- 基于TI-RTOS的CC2650DK开发(30)--- Swi官方示例
- 解析IntelliJ IDEA内部设计
- PAT1002-A+B for Polynomials
- [acm/icpc2016ChinaFinal][CodeforcesGym101194] Mr. Panda and Fantastic Beasts 后缀自动机
- Gzip压缩和解压缩以及assets目录文件的拷贝
- OC中的self和super
- 给Eclipse提速的7个技巧