1001. A+B Format (20)
来源:互联网 发布:淘宝电子烟店铺排名 编辑:程序博客网 时间:2024/06/04 20:30
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
计算a和b的和,然后标准化输出
#include<iostream>#include<cstring>#include<cstdio>#include<queue>#include<algorithm>#include<cmath>using namespace std;int main(){int a,b;cin>>a>>b;int sum=a+b;char s[100];int cnt=0,fz=1;if(sum<0) fz=0,sum*=-1;while(sum){s[cnt++]=sum%10+'0';sum/=10;}if(cnt==0){cout<<0;return 0;}if(!fz) cout<<'-';for(int i=cnt-1;i>=0;i--) {if((i+1)%3==0&&i!=cnt-1) cout<<','<<s[i]-'0';else cout<<s[i]-'0';} 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)
- 【算法】C语言实现简易的扑克牌游戏
- 软件工程学习总结
- 规范PHP代码-git hook中安装phpcs
- python推导式
- Lua Table库函数
- 1001. A+B Format (20)
- Window7+VMware Workstation+Ubuntu14.05
- TinyCrayon-iOS-SDK:强大到使人惊讶的 Mask 及切图工具库
- 继承
- powershell:调用7z,haozip解压缩文件
- Java 8 Map Filter 过滤示例
- Scala基础—文件操作示例
- ARKit从入门到精通-ARKit工作原理及流程介绍
- 回调函数