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
#include <stdio.h> #include <stdlib.h> #include <string.h> void Draw (char *str,int a,int b); int main () { long a,b; scanf("%ld %ld",&a,&b); long c=a+b; char str[9]; sprintf(str,"%d",c); int length=strlen(str); if( str[0]-'-'==0) { printf("-"); Draw(str,1,length-1); } else Draw(str,0,length-1); printf("\n"); system("pause"); return 0; } void Draw (char *str,int a,int b) { int length=b-a+1; int c=length%3,i; for (i=0;i<c;i++) printf("%c",str[i+a]); while( i<length) { if( i!=0) printf(","); printf("%c",str[i+a]); i++; printf("%c",str[i+a]); i++; printf("%c",str[i+a]); i ++; } }
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.
时间: 2024-10-15 12:27:57