PAT-甲级-1001-A+B Format
Posted tenjl-exv
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT-甲级-1001-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 case. Each case contains a pair of integers a and b where ?. The numbers are separated by a space.
Output Specification:
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
分析:将a+b存为字符数组,然后每三位分隔。
1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<string.h>
4 #define N 10
5
6
7 int main(){
8 int a,b,c;
9 char s[N];
10 scanf("%d%d",&a,&b);
11 c=a+b;
12 if(c<0){
13 c=-c;
14 printf("-");
15 }
16 sprintf(s,"%d",c);
17 for(int i=0; s[i]!=‘