PAT甲级 1001
来源:互联网 发布:java上线项目实战视频 编辑:程序博客网 时间:2024/06/05 07:53
1001. A+B Format (20)
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
使用递归进行格式化输出
#include <iostream>#include <stdio.h>using namespace std;void output(int n,int single,int cnt,int symbol){ if(n==0){ if(symbol==1)printf("-"); return; } single=n%10; cnt+=1; output(n/10,single,cnt,symbol); if(cnt%3==1&&cnt!=1){ printf("%d,",abs(single)); }else{ printf("%d",abs(single)); }}int main(){ int a,b; scanf("%d %d",&a,&b); int c=a+b; if(c<0){ output(c,0,0,1); }else if(c==0){ printf("0"); }else{ output(c,0,0,0); } 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)
- oracle中多行比较运算符(in any all)的使用
- Kubernetes的Pod网络设置
- JDE BIP的开发流程
- Java中HashMap,LinkedHashMap,TreeMap的区别
- DefaultKeyedVector和KeyedVector用法
- PAT甲级 1001
- MVVM 与RAC 网络请求
- js/JavaScript正则表达式总结 --- 常用的JavaScript正则表达式需求总结
- Hive内置运算函数,自定义函数(UDF)和Transform
- Storm基础篇
- OpenCV实现基于Zernike矩的亚像素边缘检测
- syntax error, unexpected end of file
- python的列表求并集、
- MySQL判断一个字符串是否是另一个字符串的子字符串