1001 A+B Format (20 point(s))
The situation is divided into 0 and non-0 cases. The result is 0. The case is directly output, and the non-0 case: if it is less than 0, the negative sign is output first, and then dfs uses its backtracking to output each bit.
#include <stdio.h>
#include <iostream>
using namespace std;
void dfs(int c,int cnt){
if(c == 0) return;
dfs(c/10,cnt+1);
if(cnt%3 == 0 && c>=10) putchar(',');
printf("%d",c%10);
}
int main(){
int a,b;cin>>a>>b;
if(a + b == 0) puts("0");
else{
if(a + b < 0) putchar('-');
dfs(abs(a+b),1);
}
return 0;
}