本帖最后由 dengyuli 于 2015-2-14 19:29 编辑
问题:我做了一个可以进行实数乘法的批处理,代码有点长,花了我好长时间才打好,却运行到第一个for /f时莫名其妙的退出了(for嵌套在一个if语句中)
(已解决,以下是修改后的代码:)- @echo off
- setlocal enabledelayedexpansion
- :mutiplite
- set cs1=%1
- set cs2=%2
- set "f=!cs1:~0,1!!cs2:~0,1!"
- for /l %%a in (0,1,9) do (
- set "f=!f:%%a=!"
- set f=!f: =!
- )
- set f=!f:--=!
- if "!cs1:~0,1!"=="-" set cs1=!cs1:~1!
- if "!cs2:~0,1!"=="-" set cs2=!cs2:~1!
- set cs1=!cs1: =!
- set cs2=!cs2: =!
- set w1eo=false & set w2eo=false
- set tcs1=!cs1!
- set tcs2=!cs2!
- if "!tcs1:~-1!"=="." set w1=0 & set w1eo=true
- if "!tcs2:~-1!"=="." set w2=0 & set w2eo=true
- set tcs1=!tcs1:.=!
- set tcs2=!tcs2:.=!
- set tcs1=!tcs1: =!
- set tcs2=!tcs2: =!
- if "!tcs1!"=="!cs1!" set w1=0 & set w1eo=true
- if "!tcs2!"=="!cs2!" set w2=0 & set w2eo=true
- if !w1eo!==true if !w2eo!==true set /a r=!tcs1!*!tcs2! & echo !r! & goto :eof
- if "!w1eo!"=="false " (
- for /f "delims=. tokens=1-3 usebackq" %%a in ('echo !cs1!') do (
- call :len %%b
- set w1=!zz!
- set cs1=!cs1:.=! & set cs1=!cs1: =!
- )
- ) else (
- rem meiyou
- )
- if "!w2eo!"=="false" (
- for /f "delims=. tokens=1-3 usebackq" %%a in ('echo !cs2!') do (
- call :len %%b
- set w2=!zz!
- set cs2=!cs2:.=! & set cs2=!cs2: =!
- )
- ) else (
- rem meiyou
- )
- set w1=!w1: =!
- set w2=!w2: =!
- set /a "ttw=!w1!+!w2!"
- set "tcs1=" & set "tcs2="
- call :len !cs1!
- set len1=!zz! & set len1=!len1: =! & set /a len1d1=!len1!-1
- call :len !cs2!
- set len2=!zz! & set len2=!len2: =! & set /a len2d1=!len2!-1
- set len1=!len1: =! & set len2=!len2: =!
- for /l %%a in (0,1,!len1d1!) do (
- set "tcs1=!cs1:~%%a,1!!tcs1!"
- )
- for /l %%a in (0,1,!len2d1!) do (
- set "tcs2=!cs2:~%%a,1!!tcs2!"
- )
- set cs1=!tcs1! & set cs2=!tcs2!
- set cs1=!cs1: =!
- set cs2=!cs2: =!
- for /l %%a in (0,1,!len1d1!) do (
- for /l %%b in (0,1,!len2d1!) do (
- set /a "r%%at%%b=!cs1:~%%a,1! * !cs2:~%%b,1!"
- )
- )
- for /l %%a in (0,1,!len1d1!) do (
- for /l %%b in (0,1,!len2d1!) do (
- if "!r%%at%%b:~1,1!" neq "" (
- set /a bp=%%b+1
- if not defined !r%%at%bp%! set r%%at%bp%=0
- set /a r%%at%bp%+=!r%%at%%b:~0,1!
- set r%%at%%b=!r%%at%%b:~1,1!
- ) else (
- rem nothing
- )
- )
- )
- set zz=50
- for /l %%a in (0,1,!len1d1!) do (
- set "r%%a="
- for /l %%b in (0,1,!len2d1!) do (
- set "r%%a=!r%%a!!r%%at%%b!"
- )
- )
- for /l %%a in (0,1,!len1d1!) do (
- for /l %%b in (1,1,%%a) do (
- set "r%%a=0!r%%a!"
- )
- )
- set maxstr=0
- for /l %%a in (0,1,!len1d1!) do (
- call :len !len%%a!
- if !zz! gtr !maxstr! set maxstr=!zz!
- )
- set /a maxstr-=1
- for /l %%a in (0,1,!maxstr!) do (
- for /l %%b in (0,1,!len1d1!) do (
- set "col%%a=!col%%a! !r%%b:~%%a,1!"
- )
- )
- for /l %%a in (0,1,!msxstr!) do (
- set col%%a=!col%%a: = !
- for /l %%b in (1,1,5) do (
- if "!col%%a:~0,1!"==" " set col%%a=!col%%a:~1!
- )
- )
- for /l %%a in (0,1,!maxstr!) do (
- set ljq=0
- for %%b in (!col%%a!) do (
- set /a ljq+=%%b
- )
- set r%%a=!ljq!
- )
- for /l %%a in (0,1,!maxstr!) do (
- if "!r%%a:~1,1!" neq "" (
- set /a ap=%%a+1
- for /l %%b in (!ap!,2,!ap!) do (
- if not defined !r%%b! set r%%b=0
- set /a r%%b=!r%%b!+!r%%a:~0,1!
- set r%%a=!r%%a:~1,1!
- )
- ) else (
- rem nothing
- )
- )
- set /a len2p1=!len2!+1
- set "r="
- for /l %%a in (!len2p1!,-1,0) do (
- set /a ad=%%a-1
- set ad=!ad: =!
- set "r=!r!!r%%a:~%ad%,1!"
- )
- for /l %%a in (1,1,30) do (
- if "!r:~0,1!"=="0" set r=!r:~1!
- )
- call :len !r!
- set lenr=!zz!
- if !ttw!==0 goto :eof
- set /a rstw=lenr-ttw
- set r=!r:~0,%rstw%!.!r:~-%ttw%!
- echo !f!!r!
- goto :eof
- :len
- set "str=%1"
- for /l %%a in (0,1,10) do (
- if "!str:~%%a,1!"=="" (
- set "zz=%%a"
- goto :eof
- ) else (
- rem nothing
- )
- )
- goto :eof
复制代码 不胜感激。 |