inte2000 / code_for_algo_book Goto Github PK
View Code? Open in Web Editor NEW《算法的乐趣》随书发布的代码
《算法的乐趣》随书发布的代码
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 合并出一条使用“零”的规则,将三条规则简化为两条规则:
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++;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.