zoukankan      html  css  js  c++  java
  • 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 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

    大意:

    计算  并以标准格式输出总和-也就是说,必须用逗号将数字分成三组(除非少于四位)。

    输入规格:

    每个输入文件包含一个测试用例。每个案例包含一对整数一种 和 b 哪里 这些数字用空格分隔。

    输出规格:

    对于每个测试用例,您应该输出 一种 和 b在一排。总和必须以标准格式书写。

    输入样例:

    -1000000 9
    
     

    样本输出:

    -999,991


    #include<iostream>
    #include<algorithm>
    #include<cstdlib>
    #include<cstdio>
    #include<queue>
    #include<stack>
    #include<cstring>
    #include<string.h>
    #include<cmath>
    using namespace std;
    const int maxn=1010;
        
    
    int main(){
        int a,b;
        scanf("%d %d",&a,&b);
        int c=a+b;
        c=abs(c);
        int d[maxn];
        int i=0;
        while(c){
            d[i]=c%10;
            c/=10; 
            i++;
        }
        if(a+b<0){
            printf("-");
        }
        if(a+b==0){
            printf("0
    ");
            return 0;
        }
        for(int j=i-1;j>=0;j--){
            printf("%d",d[j]);
            if((j)%3==0&&j>0){
                printf(",");
            }
            
            
        }
        printf("
    "); 
        
        return 0;
    }
  • 相关阅读:
    矩阵游戏|ZJOI2007|BZOJ1059|codevs1433|luoguP1129|二分图匹配|匈牙利算法|Elena
    BZOJ3262: 陌上花开
    BZOJ1176: [Balkan2007]Mokia
    BZOJ1261: [SCOI2006]zh_tree
    BZOJ2004: [Hnoi2010]Bus 公交线路
    BZOJ1066: [SCOI2007]蜥蜴
    BZOJ1294: [SCOI2009]围豆豆Bean
    BZOJ2756: [SCOI2012]奇怪的游戏
    BZOJ1857: [Scoi2010]传送带
    BZOJ1237: [SCOI2008]配对
  • 原文地址:https://www.cnblogs.com/dreamzj/p/13855254.html
Copyright © 2011-2022 走看看