PAT 1001

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 9 

Sample Output

-999,991 
主要注意两点 :
  1. 输出时要注意逗号,如1000要输出1,000
  2. 要注意后面部分数字的前置0,如1010,要输出1,010,而不是1,10
代码
 1 #include <stdio.h>
 2 int main()
 3 {
 4     int a,b,sum;
 5     int arr[];
 6     while(scanf("%d%d",&a,&b) != EOF){
 7         sum = a+b;
 8         if(sum == ){
 9             printf("0\n");
             break;
         }
         else if(sum < ){
             printf("-");
             sum = sum * -;
         }
         int i = ;
         while(sum){
             arr[i++] = sum % ;
             sum = sum / ;
         }
         printf("%d",arr[--i]);
         for(--i;i >= ;--i){
             printf(",%03d",arr[i]);
         }
         printf("\n");
     }
     return ;
 }

上一篇:VSCode 配置快速输入Python的Main函数方法


下一篇:[学习笔记]设计模式之Factory Method