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 }
  • 相关阅读:
    类型转换
    struts2默认拦截器
    struts2自定义拦截器
    struts2之I18N
    代理模式
    抽象类 abstract class 接口
    java基础题
    final
    内部类
    tomcat 端口占用问题解决
  • 原文地址:https://www.cnblogs.com/ligen/p/4336971.html
Copyright © 2011-2022 走看看