本帖最后由 happy886rr 于 2016-11-2 20:28 编辑
题目的数字太小了。- @echo off
- REM 支持天文数字,不限长度,小数也行,已分装为函数,直接呼。
- call :MULTIPLICATION %random%×%random%×%random%×%random%×%random%×%random%×%random%×%random%
- pause&exit /b
-
- def MULTIPLICATION():
- {
- :MULTIPLICATION <表达式>
- set "expression=%1"
- if "!CHECK_ENABLE_DELAYED_EXPANSION!"=="%CHECK_ENABLE_DELAYED_EXPANSION%" (SETLOCAL) else (SETLOCAL ENABLEDELAYEDEXPANSION)
- set RESULT=1&set "expression=%expression:×= %"
- for %%a in (!expression!) do (
- CALL :CALCULATE !RESULT! %%a RESULT
- )
- echo 计算%1
- echo =!RESULT!
- ENDLOCAL
- GOTO :EOF
- }
- def CALCULATE():
- {
- :CALCULATE <被乘数> <乘数> [积]
- for /f "tokens=1,2 delims=." %%a in ("%1") do (
- set A1=%%a&set A=!A1!%%b
- if "%%b"=="" (set PA=0) else (
- set A2=%%b
- for %%i in (512 256 128 64 32 16 8 4 2 1) do (
- if not "!A2:~%%i!"=="" (
- set/a PA+=%%i
- set "A2=!A2:~%%i!"
- )
- )
- if "!A2:~1!"=="" (set/a PA+=1)
- )
- )
- for /f "tokens=1,2 delims=." %%a in ("%2") do (
- set B1=%%a&set B=!B1!%%b
- if "%%b"=="" (set PB=0) else (
- set B2=%%b
- for %%i in (512 256 128 64 32 16 8 4 2 1) do (
- if not "!B2:~%%i!"=="" (
- set/a PB+=%%i
- set "B2=!B2:~%%i!"
- )
- )
- if "!B2:~1!"=="" (set/a PB+=1)
- )
- )
- CALL :CUTNUM !A! A NA
- CALL :CUTNUM !B! B NB
- set/a "N=NA+NB,PO=PA+PB"
- for /l %%i in (1 1 !N!) do (
- for /l %%j in (1 1 %%i) do (
- set/a j=%%i-%%j+1
- if defined A[%%j] (
- if defined B[!j!] (
- set/a sum=A[%%j]*B[!j!]+sum
- )
- )
- )
- set/a s=sum+1000
- set sum=!sum:~0,-3!
- set pul=!s:~-3!!pul!
- )
- if !PO! equ 0 (
- for /l %%i in (1 1 10) do (
- if "!pul:~0,1!"=="0" (
- set pul=!pul:~1!
- )
- )
- set "%3=!pul!"
- ) else (
- set pre=!pul:~0,-%PO%!
- for /l %%i in (1 1 20) do (
- if "!pre:~0,1!"=="0" (
- set pre=!pre:~1!
- )
- )
- if not defined pre (set pre=0)
- set "%3=!pre!.!pul:~-%PO%!
- )
- for /l %%i in (1 1 !N!) do (set "A[%%i]="&set "B[%%i]=")&set "pul="&set/a "PA=0,PB=0,PO=0"
- GOTO :EOF
- }
- def CUTNUM():
- {
- :CUTNUM <待切分数> <数据类型> [切分组数]
- set num=%1
- if "!num:~-3!"=="!num:~-4!" (
- set %2[1]=!num!
- set %3=1
- GOTO :EOF
- )
- for /l %%i in (1 1 365) do (
- if "!num:~0,-3!"=="" (
- set/a %2[%%i]=!num!
- set %3=%%i
- GOTO :EOF
- )
- set/a %2[%%i]=1!num:~-3!-1000
- set num=!num:~0,-3%!
- )
- GOTO :EOF
- }
复制代码
|