A1001. A+B Format (20)

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 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <algorithm>
 4 #include <string.h>
 5 using namespace std;
 6
 7 const int maxn =100010;
 8 int a,b,sum;
 9
10
11 int main(int argc, char* argv[])
12 {
13     scanf("%d%d",&a,&b);
14     sum=a+b;
15     int num[10];
16     if(sum<0)
17     {
18     printf("-");
19     sum=-1*sum;
20     }
21     int len=0;
22     if(sum==0)num[len++]=0;
23     while(sum)
24     {
25     num[len++]=sum%10;
26     sum/=10;
27     }
28     for(int k=len-1;k>=0;k--)
29 {
30 printf("%d",num[k]);
31 if(k>0&&k%3==0)printf(",");
32 }
33     system("pause");
34     return 0;
35 }
时间: 2024-10-19 12:56:04

A1001. A+B Format (20)的相关文章

PAT A1001 A+B Format

PAT A1001 A+B Format 题目描述: 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 Specification: Each input file contains one test ca

A+B Format (20)

1001. A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 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 fi

PAT1001. A+B Format (20)

1001. A+B Format (20) 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 cont

1001. A+B Format (20) ——PAT (Advanced Level) Practise

题目信息: 1001. A+B Format (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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

【PAT】1001. A+B Format (20)

1001. A+B Format (20) 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 cont

PAT 甲级 1001 A+B Format (20)(20 分)

1001 A+B Format (20)(20 分) 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

PAT 1001. A+B Format (20)

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 integer

1001. A+B Format (20)

时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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 inp

PAT甲级 1001. A+B Format (20)

题目原文: 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 i