本帖最后由 flashercs 于 2020-6-17 06:33 编辑
- @echo off
- REM 查找step=1的等差数列arithmetric progression,长度为arraylen
- setlocal enabledelayedexpansion
- set in=series.txt
- set out=ArithmetricProgression.txt
- set arraylen=4
- set step=1
- if %arraylen% lss 1 (
- echo 序列长度必须是大于0的整数
- goto end
- )
- REM init: clear array
- for /f "delims==" %%A in ('2^>nul set arr[') do set %%A=
- set /a i=begin=0,end=begin+arraylen-1
- (
- for /f "delims=" %%A in (%in%) do (
- if !i! gtr %begin% (
- set /a p=i-1
- for %%P in (!p!) do set /a sub=1%%A-1!arr[%%P]!
- if !sub! neq %step% (
- set /a i=begin
- )
- )
- set arr[!i!]=%%A
- if !i! equ %end% (
- for /l %%B in (%begin%,1,%end%) do echo !arr[%%B]!
- echo.
- set /a i=begin
- ) else (
- set /a i+=1
- )
- )
- )
-
- :end
- endlocal
- pause
- exit /b
复制代码
|