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

    输入描述:

    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.



    输出描述:

    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.

    输入例子:

    -1000000 9

    输出例子:

    -999,991


    #include<stdio.h>
    #include<math.h>
    int str(int a){
        int n=0;
        while(a){
            n++;
            a/=10;
        }
        return n;
    }
    int main(){
        int a,b,c,m,mm;
        scanf("%d%d",&a,&b);
        m=a+b; 
        if(m<0) mm = -m;
        else mm = m;
        c = str(a+b);
        if(c<=3) printf("%d",m);
        if(c>3&&c<=6){
        printf("%d,%03d",m/1000,mm%1000);
        }
        if(c>6){
            printf("%d,%03d,%03d",m/1000000,mm/1000%1000,mm%1000);
        }
    }

    这个题没什么特点,反复调整了几次,做完之后感觉并没有利用什么优秀的想法,于是看了一下别人的,好像大家都差不多,意外发现一个博客,实行了一下,好像DEV里不能用,日后有空再看一下。

  • 相关阅读:
    input 放大镜
    记住密码弹出事件
    thinkphp修改及编写标签库,编辑器的使用
    thinkphp 配合mongodb
    缓存技术
    php面试题目
    pdo 整套类的封装,保存修改查询
    mongodb 的备份恢复导入与导出
    mongodb 分组查询
    smarty 模板的入门使用
  • 原文地址:https://www.cnblogs.com/zhangzimu/p/9181032.html
Copyright © 2011-2022 走看看