PAT 1001. A+B Format
#include<stdio.h> int a, b; int sum; int main(){ while (scanf("%d %d", &a, &b)!=EOF){ sum = a + b; if (sum < 1000&&sum>-1000)printf("%d\n", sum); else{ int sum1 = sum % 1000; int sum2 = sum / 1000; int sum3 = 0; if (sum2 != 0){ sum3 = sum2 / 1000; } sum2 = sum2 % 1000; if (sum3 != 0){ printf("%d,%03d,%03d\n", sum3 % 1000, sum2 < 0 ? -sum2 : sum2, sum1 < 0 ? -sum1 : sum1); } else printf("%d,%03d\n", sum2, sum1<0?-sum1:sum1); } } }