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;
}
本文介绍了一个简单的C++程序,该程序实现两个整数相加的功能,并以特定的格式输出结果。具体而言,程序首先读取两个整数,计算它们的和,然后将和数以逆序逗号分隔的形式打印出来。
285

被折叠的 条评论
为什么被折叠?



