本帖最后由 qixiaobin0715 于 2022-8-4 16:43 编辑
有样学样,适合数值小于十万。来一个不用goto的:- @echo off
- setlocal enabledelayedexpansion
- set str=九万九千九百九十九
- set str=!str:零=!
- for %%i in (一 二 三 四 五 六 七 八 九) do (
- set /a x+=1
- set _%%i=!x!
- )
- set x=1
- for %%i in (十 百 千 万) do (
- set /a x*=10
- set #%%i=!x!
- set %%i=1
- )
- for /l %%i in (0,2,8) do (
- set var=!str:~%%i,2!
- if not "!var!"=="" (
- if not "!var:~1!"=="" set /a m1=!var:~1!
- set /a m2=!var:~,1!
- if "!m1!"=="1" (
- set /a n+=_!var:~,1!*#!var:~1!
- ) else if "!m2!"=="1" (
- set /a n+=#!var:~,1!+_!var:~1!
- ) else (
- set /a n+=_!var!
- )
- set m1=
- set m2=
- )
- )
- echo,!n!
- set n=
- pause
复制代码
|