国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 长兴县| 来宾市| 青海省| 大洼县| 新营市| 萨嘎县| 平南县| 和顺县| 富源县| 平武县| 正镶白旗| 布尔津县| 神池县| 呼伦贝尔市| 甘肃省| 银川市| 东乡族自治县| 西宁市| 锡林浩特市| 邢台县| 新田县| 平谷区| 宜宾县| 浏阳市| 汉阴县| 永吉县| 天柱县| 三江| 德安县| 邹城市| 望城县| 高尔夫| 蒲江县| 松潘县| 理塘县| 正定县| 庄河市| 济源市| 财经| 牙克石市| 湟中县|