1001. A+B Format (20)
来源:互联网 发布:独立电影节知乎 编辑:程序博客网 时间:2024/06/16 11:45
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<vector>#include<stack>using namespace std;int main(){stack<char> v;int a,b;cin>>a>>b;int c=a+b;int sign=0;if(c==0){cout<<"0"<<endl;return 0;}if(c<0){sign=1;c=0-c;}int count=0;int flag=0;while(c>0){int temp=c%10;count++;v.push(temp+48);if(count%3==0 && count>0){flag++; v.push(44);}c=c/10;}if((v.size()-flag)%3==0)v.pop();if(sign==1){cout<<'-';}while(!v.empty()){cout<<v.top();v.pop();}system("pause");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语言】求数值的正数次方
- github 的一些问题汇总
- xml配置文件不能被正确解析的特殊符号的处理方法
- DWR中js调用Java方法的参数及返回值
- R语言的告警”条件的长度大于一,因此只能用其第一元素“的解决办法
- 1001. A+B Format (20)
- JAVA三大特性之三---多态性
- 安卓高德地图开发自定义线路规划(按着自己定义的经纬度规划线路)
- android style之我的理解
- 解决pl/sql developer 中文字段显示乱码或无法用中文作查询条件的问题
- python重置变量 sys.defaultencoding
- Unity检测目标点是否在扇形攻击范围内
- poj 3321 Apple Tree (树状数组+DFS)
- javacript检查是否为正整数,检查是否是合法的字符串,计算一个字符串的字节长度