1001. A+B Format (20)
来源:互联网 发布:薛之谦的淘宝店uujuly 编辑:程序博客网 时间:2024/05/29 10:02
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>int main(){ int i=0,flag=0,a,b,sum; char str[9]; while(scanf("%d%d",&a,&b)!=EOF) { flag=0; sum = a+b; if(sum<0) { sum = -sum; printf("-"); } if(sum==0){printf("0");} for(i=0;sum>0;i++) { str[i] = sum%10+'0';//数字转换为字符 sum = sum/10; if(flag == 2 && sum!=0) { i++; str[i]=','; flag=0; } else flag++; } i--; for(;i>=0;i--) { printf("%c",str[i]); } printf("\n"); } 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)
- 济南网站制作|济南网站建设|济南网站设计|济南网页设计公司|济南软件开发|济南天猫淘宝店铺装修不懂得问我
- Xcode中project.pbxproj合并冲突的解决
- Android--activity配置与activity之间的通讯(一)
- 素数筛选模板
- box-flex: 1
- 1001. A+B Format (20)
- hbase 笔记
- 方向梯度直方图(HOG,Histogram of Gradient)学习笔记二 HOG正篇
- 数学题--On Sum of Fractions
- putty 文件传输 pscp
- 直接型FIR滤波器的fpga实现
- ThinkPHP备忘
- BFS模板
- plsql 注册码|plsql8注册码