PAT (Advanced Level) Practise 1001 A+B Format
来源:互联网 发布:admin.seo.com.cn 编辑:程序博客网 时间:2024/05/28 05:13
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 <math.h>using namespace std;int main(){ int n,m,sum,su; char a[100]; while(~scanf("%d%d",&n,&m)) { sum=m+n; su=fabs(sum); if(su==0) printf("0\n"); else { int k=0,j=0; while(su>0) { a[k++]=su%10+'0'; su=su/10; j++; if(j%3==0&&su!=0) a[k++]=','; } if(sum<0) a[k++]='-'; for(int i=k-1;i>=0;i--) printf("%c",a[i]); printf("\n"); } } return 0;}
0 0
- 浙大PAT (Advanced Level) Practise 1001 A+B Format (20)
- PAT (Advanced Level) Practise 1001 A+B Format (20)
- PAT (Advanced Level) Practise 1001A+B Format (20)
- PAT (Advanced Level) Practise —1001:A+B format
- PAT (Advanced Level) Practise 1001A+B Format (20)
- PAT (Advanced Level) Practise 1001 A+B Format
- PAT (Advanced Level) Practise 1001. A+B Format
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- PAT (Advanced Level) Practise 1001. A+B Format (20)
- PAT Advanced Level 1001:A+B Format
- PAT-PAT (Advanced Level) Practise 1001. A+B Format (20) 【二星级】
- PAT (Advanced Level) Practise —— 1001. A+B Format (20)
- 1001. A+B Format (20) ——PAT (Advanced Level) Practise
- PAT(Advanced level) 1001. A+B Format
- Vue.js 是什么
- Cartographer_ROS初探
- 深度学习算法之YOLOv2
- 每天进步一点点——五分钟理解一致性哈希算法(consistent hashing)
- IO流_如何让对象的成员变量不被序列化
- PAT (Advanced Level) Practise 1001 A+B Format
- Android注册界面之Md5对用户信息加密
- 算法课不定期心得整理——一些递归式的求解心得
- java自学之路(Java从入门到精通)
- iOS
- JavaMail——基础篇
- 自己看一些零散源码的小结
- Python--lambda表达式学习
- Git核心用法