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

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

1001. A+B Format的相关文章

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

1001. A+B Format (20) (数学啊 ZJU_PAT)

题目链接:http://www.patest.cn/contests/pat-a-practise/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 conta

PAT甲级考试题库1001 A+B Format 代码实现及相关知识学习

准备参加九年九月份的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). 计算a+b的值并以一定格式输出其和sum(数字需要

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

PAT 甲级 1001 A+B Format

https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400 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). Inpu