![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-09-15 12:59 |
47,812 topics / 349,917 posts / today 0 new / 48,268 members |
| DOS批处理 & 脚本技术(批处理室) » [Joint Participation][Challenge the Approach] Arabicizing Chinese Numerals |
| Printable Version 6,809 / 11 |
| Floor1 namejm | Posted 2007-01-03 12:18 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
A couple of days ago, brother 无奈何 proposed the idea of converting lowercase monetary amounts into uppercase: Using batch files to convert numeric amounts to uppercase, which drew in quite a few experts, and some of the solutions were really eye-opening.
Brother qzwqzw brought up the idea of doing the reverse conversion. I thought it was very interesting, so I tried writing a bit of code. There are no error-checking statements, and I haven’t done any code simplification either. I’m posting it for everyone to test, and I also hope you can provide different solutions: [ Last edited by namejm on 2007-1-3 at 08:18 PM ] |
|
| Floor2 qzwqzw | Posted 2007-01-03 23:23 |
| 银牌会员 Posts 636 Credits 2,343 | |
|
Your code has a problem when tested with 捌仟零叁万. Find exactly where it is yourself
———————————————————————————————— Posting another complete mutual-conversion code segment I deliberately added some invalid numbers in the test I’m very dissatisfied with the RMB2Num section First, there is no good checking; findtsr does not support regular expressions for double-byte characters Second, there is no good structure; defects in the design of the algorithm and data structure have led to defects in the code structure [ Last edited by qzwqzw on 2007-1-3 at 11:22 AM ] |
|
| Floor3 namejm | Posted 2007-01-04 00:10 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
Hehe, the testing wasn’t rigorous. I’m checking for the error now.
|
|
| Floor4 qzwqzw | Posted 2007-01-04 00:30 |
| 银牌会员 Posts 636 Credits 2,343 | |
|
R3 only adjusted the structure of the RMB2Num section
Because the algorithm and data structure were not changed So some inherent defects merely changed their form of expression For example, nested ifs, redundant else set, and so on [ Last edited by qzwqzw on 2007-1-3 at 11:34 AM ] |
|
| Floor5 namejm | Posted 2007-01-04 01:58 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
After modification, the code in the top post can already handle Chinese numerals like 捌仟零叁万 and 捌仟零叁拾万 (thanks to qzwqzw for pointing out these problems on 2F and 6F). Please keep testing it.
RE qzwqzw: If you could put the solution idea in the code, it would make it easier for others to understand your algorithm — I started out forcing myself to read your code -_-||. [ Last edited by namejm on 2007-1-3 at 03:10 PM ] |
|
| Floor6 qzwqzw | Posted 2007-01-04 02:32 |
| 银牌会员 Posts 636 Credits 2,343 | |
|
Continue testing with 捌仟零叁拾万 and a problem appears
———————————————————————————————— In my code The :Num2RMB section is relatively simple: directly replace the digits and positional units by place, then do step-by-step replacements for the zero/整 issues The :RMB2Num section is more troublesome. Since the algorithm is not mature, I don’t want to explain too much Mainly it scans tbl2 and rmb in sync When the two are aligned, it performs digit replacement and shifts both in sync Otherwise, it shifts %tbl2% alone to make it align, while using 0 to fill empty positions The code itself already roughly reflects the outline of the algorithm Maybe my comments would instead increase the difficulty of reading, so I left them all out One clear line of code is better than ten vague comments |
|
| Floor7 namejm | Posted 2007-01-04 04:07 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
RE qzwqzw:
A piece of code really does not need too many comments, but if the idea can be attached along with it, the effect is better, because the explanation of the idea lets people know the general flow of the code from the very beginning. When there is too much code, they won’t get dizzy from jumping around and forget the purpose of each section of code. Of course, providing an explanation of the idea is only to let others understand the code better, for others’ convenience. It is not required content. |
|
| Floor8 youxi01 | Posted 2007-01-04 07:45 |
| 高级用户 Posts 247 Credits 846 From 湖南==》广东 | |
|
Here is a more “alternative” one. At present it only supports numbers under 100 million. Testing is welcome!
|
|
| Floor9 tigerpower | Posted 2007-01-04 10:48 |
| 中级用户 Posts 99 Credits 377 | |
|
Haha, it’s rare for me to write such a long pure batch file :)
@echo off [ Last edited by tigerpower on 2007-1-6 at 12:24 PM ] |
|
| Floor10 tao0610 | Posted 2007-01-05 08:28 |
| 高级用户 Posts 218 Credits 579 | |
|
Posting one calculated by an arithmetic method.
It must be less than 2147483648, and can only be an integer |
|
| Floor11 vipchenlang | Posted 2007-11-30 23:51 |
| 新手上路 Posts 3 Credits 6 | |
|
I’ve learned something again!!!!!!!!!!!!!!!!!!!!!
|
|
| Floor12 new999 | Posted 2008-12-03 18:42 |
| 新手上路 Posts 1 Credits 1 | |
Originally posted by youxi01 at 2007-1-4 07:45: |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |