1001. A+B Format (20)

原创 2015年07月09日 14:35:10

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<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;
}



版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

PAT1001. A+B Format(20)

最近开始每天做一道PAT练手,下面是PAT1001的题目。 Calculate a + b and output the sum in standard format -- that is, th...

1001. A+B Format (20)

1001. A+B Format (20)

1001. A+B Format (20)

Calculate a + b and output the sum in standard format – that is, the digits must be separated into g...

PAT-A 1001. A+B Format (20)

PAT-A 1001. A+B Format (20) 逗号输出有坑……

1001. A+B Format (20)

1001. A+B Format (20)Calculate a + b and output the sum in standard format – that is, the digits mus...

1001. A+B Format (20)

Calculate a + b and output the sum in standard format -- that is, the digits must be separated into ...

[PAT]1001. A+B Format (20)

Calculate a + b and output the sum in standard format -- that is, the digits must be separated into ...

PAT 1001. A+B Format (20)(字符串转换)

题目1001. A+B Format (20)时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Calculate...

1001. A+B Format (20) C++

问题描述: Calculate a + b and output the sum in standard format – that is, the digits must be separated ...

1001. A+B Format (20)

1001. A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B ...
  • fynjy
  • fynjy
  • 2015-07-06 13:35
  • 178
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)