易讀版:- @echo off&setlocal enabledelayedexpansion
- del testinbathome.txt 2>nul>nul
- for /f "tokens=1,2,3,4,5 delims= " %%a in (1.txt) do (
- set ORG=%%a %%b %%c %%d %%e
- for %%f in (!ORG!) do (
- set /a looptime+=1
- ::去除字串左前的所有0
- set /a var!looptime!=-11%%f+10%%f+1%%f
- )
- call :step !var1! !var2! !var3! !var4! !var5!
- set looptime=
- )>>testinbathome.txt
- start testinbathome.txt
- <
- :step
- ::判斷是否順數 , 非順數才繼續嘗試整除
- set str=set/a nub=%5-%4+%4-%3+%3-%2+%2-%1
- for /f %%i in ('!str!') do (
- set /p=!ORG! <nul
- if "%%i" EQU "4" (
- echo 連續的字串
- ) else (
- ::非連續的字串
- call :step2 !var1! !var2! !var3! !var4! !var5!
- )
- goto :eof
- )
- :step2
- ::判斷數字能否全為2-9之倍數 , 和判斷奇偶數
- set str=%10 %20 %30 %40 %50
- ::for語句[2,3,5,9] 可切換成 [2,3,4,5,6,7,8,9] , 則變成判繼2至9的所有倍數
- for %%Z in (2,3,5,9) do (
- call :step3 %%Z
- if "!about%%Z!" EQU "00000" (
- set /p=整除於[%%Z]<nul
- if "%%Z"=="2" (set /p=, 偶數字串 , <nul)
- )else if "!about%%Z!%%Z" == "555552" (set /p=奇數字串<nul))
- )
- echo.
- goto :eof
- )
- :step3
- ::數字2-9通用的整除計算語句
- for /f "tokens=1,2,3,4,5 delims= " %%i in ('echo !str!') do set/a A=%%i/%1 ,B=%%j/%1,C=%%k/%1,D=%%m/%1,E=%%l/%1&&set about%1=!A:~-1,1!!B:~-1,1!!C:~-1,1!!D:~-1,1!!E:~-1,1!
复制代码 精簡版:- @echo off&setlocal enabledelayedexpansion
- del testinbathome.txt 2>nul>nul
- for /f "tokens=1,2,3,4,5 delims= " %%a in (1.txt) do (
- set ORG=%%a %%b %%c %%d %%e
- for %%f in (!ORG!) do set /a looptime+=1&&set /a var!looptime!=-11%%f+10%%f+1%%f
- set/a str=!var5!-!var4!+!var4!-!var3!+!var3!-!var2!+!var2!-!var1!
- set /p=!ORG! <nul
- if "!str!" EQU "4" set /p=連續的字串<nul
- for %%Z in [color=Red](2,3,4,5,6,7,8,9)[/color] do (
- set/a A=!var1!0/%%Z ,B=!var2!0/%%Z,C=!var3!0/%%Z,D=!var5!0/%%Z,E=!var5!0/%%Z
- set about%%Z=!A:~-1,1!!B:~-1,1!!C:~-1,1!!D:~-1,1!!E:~-1,1!
- if "!about%%Z!%%Z" == "555552" set mark=1&&set /p=奇數字串<nul
- if "!about%%Z!" EQU "00000" (
- if "%%Z"=="2" (
- set mark=2&set /p=偶數字串 , [%%Z]<nul
- ) else (
- if !mark!==1 set /p=, <nul
- set mark=2&set /p=[%%Z]<nul
- )
- )
- if !mark!9==2%%Z set /p=之倍數<nul
- )
- echo.
- set looptime=&set mark=0
- )>>testinbathome.txt
- start testinbathome.txt
复制代码 測試文件[1.txt]- 01 02 03 04 05
- 01 02 03 04 06
- 01 02 03 04 07
- 01 02 03 04 08
- 01 02 03 04 09
- 01 02 03 04 10
- 01 02 03 04 11
- 02 03 04 05 06
- 02 04 06 08 10
- 03 06 09 12 15
- 01 03 05 07 09
- 05 10 15 20 25
- 06 09 15 27 33
- 01 04 07 10 13
- 01 05 09 13 17
- 01 06 11 16 21
- 01 07 13 19 25
- 01 08 15 22 29
- 01 09 18 26 34
- 03 11 15 21 23
- 06 10 18 22 28
- 04 06 08 10 12
- 06 07 08 09 10
- 23 24 25 26 27
- 06 10 20 22 28
- 28 29 30 31 32
- 09 18 27 36 99
- 099 0117 0234 0594 07992
- 0090 0099 0909 0594 07992
- 02889 2898 02997 03789 04293
- 0029 030 00031 32 033
- 29 00030 031 00000032 0033
- 2 0000004 006 00008 10
- 550 00660 000770 880 0990
- 33 39 63 69 99
- 44 88 124 164 204
- 40 80 120 160 200
- 06 12 18 24 30
- 07 14 21 28 35
- 08 16 24 32 40
- 01 03 06 07 09
- 09 18 27 36 99
复制代码 我把他直接寫成可分類 : 奇數、偶數、順序字串、和分辨[1-9]的倍數
另外因不肯定你只是用來處理2位數組 , 也不肯定數目前必然只有1個零 , 所以也把它寫成可以通用處理[測試文件]那些古怪格式了
另外也因不肯定你只是用來處理[3]和[5]的倍數 , 所以也把它寫成可以通用分辨[1-9]的倍數。如果需要改回只處理3和5的倍數 , 你可把[精簡版:](2,3,4,5,6,7,8,9) 一句改成(2,3,5)就可以了
第一個[易讀版:]的代碼是方便你讀和修改的 , 所以盡量把運作分類和每部份寫註解了。如果你想增加判斷字串方法 , 應該你再增加 標籤/算式 , 再call這標籤就成了 |