Git Product home page Git Product logo

code_for_algo_book's People

Contributors

inte2000 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

code_for_algo_book's Issues

阿拉伯数字转中文数字"零"的使用规则可有矛盾?

Page 48 中文数字对“零”的使用总结起来有以下三条规则。

  • 规则 1: 以10000为小节,小节的结尾即使是 0,也不使用“零”。
  • 规则 2: 小节内两个非 0 数字之间要使用“零”。
  • 规则 3: 当小节的“千”位是 0 时,若本小节的 前一小节 无其他数字,则不用“零”,否则就要用“零”

考虑数字 1 0000,按照规则 1,小节的结尾是 0000 所以不使用“零”;按照规则 3,该小节的千位是 0,并且前一小节有其他数字 1,所以使用“零”,1 0000 的中文表示为:一万,所以认为规则 1 的优先级大于规则 3

考虑数字 1 0000 0100,对于 0100 按照规则 3,前面一小节 0000 没有除了 0 以外的其他数字,所以不用“零”,对于 0000 规则 1 和规则 3 都适用,而规则 1 的优先级大于规则 3,所以不用“零”,所以 1 0000 0100 根据三条规则表示为:一亿一百

填写票据和结算凭证的基本规定
阿拉伯数字中间有“0”时,中文大写金额要写“零”字。阿拉伯数字中间连续有几个“0”时,中间可以只写一个“零”字

根据上面的规则,1 0000 0100 应该表示为:一亿零一百

以为可以从规则 1 和 规则 3 合并出一条使用“零”的规则,将三条规则简化为两条规则:

  • 规则 1: 小节内两个非 0 数字之间要使用“零”。
  • 规则 2: 小节非 0000 千位为 0 该小节前有其他数字

这样也可以和书中提供的代码直接对应:

    while(num > 0)
    {
        unsigned int section = num % 10000;
        if(needZero)
        {
            chnStr.insert(0, chnNumChar[0]);
        }
        SectionToChinese(section, strIns);
        /*是否需要节权位?*/
        strIns += (section != 0) ? chnUnitSection[unitPos] : chnUnitSection[0]; 
        chnStr.insert(0, strIns);
        /*千位是0?需要在下一个section补零*/
        needZero = (section < 1000) && (section > 0); 
        num = num / 10000;
        unitPos++;
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.