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

    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<cstdio>
     2 #include<iostream>
     3 #include<string.h>
     4 using namespace std;
     5 int main(){
     6     int a, b, c, sign = 0, bt;
     7     char prt[30];
     8     scanf("%d%d", &a, &b);
     9     c = a + b;
    10     if(c < 0){
    11         c = -1 * c;
    12         sign =1;
    13     }
    14     int i = 0, tag = 0;
    15     do{
    16         bt = c % 10;
    17         c = c / 10;
    18         prt[i++] = '0' + bt;
    19         tag++;
    20         if(tag != 0 && tag % 3 == 0){
    21             prt[i++] = ',';
    22         }
    23     }while(c != 0);
    24     if(prt[i - 1] != ',')
    25         prt[i] = '';
    26     else
    27         prt[i - 1] = '';
    28     if(sign == 1)
    29         printf("-");
    30     for(int j = strlen(prt) - 1; j >= 0; j--)
    31         printf("%c", prt[j]);
    32     cin >> a;
    33     return 0;
    34 }
    View Code

    注意:在整个数字的最高位前不能有逗号。

  • 相关阅读:
    IPC——信号量
    IPC——命名管道
    IPC——匿名管道
    IPC——信号
    管道和命名管道
    Oracle业务用户密码过期问题的解决
    Oracle获取数据库中的对象创建语句
    RAC禁用DRM特性
    配置Server Side TAF
    同一环境下新建Standby RAC库
  • 原文地址:https://www.cnblogs.com/zhuqiwei-blog/p/8442154.html
Copyright © 2011-2022 走看看