您的位置:首页 > 其它

PAT刷题

2015-12-25 18:38 316 查看
1001. A+B Format(20)

#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

char str[100];

int main(){
	// freopen("I-in.txt", "r", stdin);
	int a, b;
	scanf("%d%d", &a, &b);
	int c = a + b;
	int flag = 0;
	if(c < 0) flag = 1;
	int pos = 1;
	int tmp = abs(c);
	while(tmp){
		if(pos%4 == 0)str[pos++] = ',';
		str[pos++] = '0' + tmp % 10;
		tmp /= 10;
	}
	if(flag) printf("-");
	for(int i = pos - 1; i >= 1; i--)
		printf("%c", str[i]);
	if(!c) printf("0");
	printf("\n");
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: