国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

PAT A 1001. A+B Format (20)

2019-11-08 02:08:11
字體:
供稿:網(wǎng)友

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

// 題目分析:

沒有難點,可以有多種實現(xiàn)方法,此處練習堆棧操作

// 代碼

#include <iostream>#include <string>#include <stack>using namespace std;int main(){	int a,b;	cin>>a>>b;	int c=a+b;	if(c<0){		c=-c;		cout<<'-';	}else if(c==0){		cout<<0;		return 0;	}	stack<char> s;	int count=0;//計數(shù)器	while(c!=0){		if(count%3==0&&count!=0){			s.push(',');		}		s.push(c%10+'0');		count++;		c/=10;	}	while(!s.empty()){		cout<<s.top();		s.pop();	}	system("pause");	return 0;}
// 結(jié)果


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 泰安市| 永德县| 衡水市| 左权县| 康定县| 辛集市| 社会| 建湖县| 太和县| 同心县| 新昌县| 岳西县| 平潭县| 山丹县| 鹤峰县| 普兰店市| 江华| 奉节县| 临澧县| 库车县| 南陵县| 湄潭县| 阜城县| 怀宁县| 郑州市| 吐鲁番市| 邓州市| 华池县| 临汾市| 怀宁县| 扬中市| 鱼台县| 南充市| 固始县| 丽水市| 乌拉特后旗| 醴陵市| 丹阳市| 赤水市| 枣庄市| 科技|