zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    MYSQL索引使用
    事务的概念是什么,有哪些基本属性?
    springboot和springmvc的区别
    List、Map、Set的区别与联系
    MyBatis-动态SQL
    MyBatis-映射文件
    MyBatis操作数据库及全局配置文件
    Jmeter的基本使用
    MySQL索引优化
    MySQL索引
  • 原文地址:https://www.cnblogs.com/ligen/p/4336971.html
Copyright © 2011-2022 走看看