1001. A+B Format (20)
来源:互联网 发布:设有数组定义,x 编辑:程序博客网 时间:2024/06/04 00:42
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 <iostream>#include <stdio.h>#include <string.h>using namespace std;int main(){ int a,b; cin>>a>>b; int sum=a+b; if(sum<0){ cout<<"-"; sum=-sum; } char *p = new char[20]; sprintf(p, "%d",sum); for(int i=0;i<strlen(p);i++){ if((strlen(p)-i)%3==0&&i!=0) cout<<","; cout<<p[i]; } cout<<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)
- Unity Update 详解
- #学习笔记#(38)js轮播图
- 《笨办法学Python》 第37课手记
- Android开发学习之路--UI之简单聊天界面
- [LeetCode]53. Maximum Subarray
- 1001. A+B Format (20)
- 1002. A+B for Polynomials (25)
- 网易新闻首页demo
- 1003. Emergency (25)
- HDU 3853 LOOPS 概率DP 期望
- PyMySQL与Django的结合
- 1004. Counting Leaves (30)
- 优先级队列——PriorityQueue
- spark源码学习(三)---worker源码分析-worker启动driver、executor分析