在循环中非常高效的表驱动法: | @echo off&setlocal enabledelayedexpansion | | set "tmp= 0 9 8 7 6 5 4 3 2 1" | | for /l %%a in (0 1 4) do set var=!tmp: =%%a!!var! | | for /f "delims=" %%a in (a.txt) do ( | | set str=%%a | | set m=!str: =!!str: =!!var! | | if "1!m:~100,2!" gtr "1!max!" ( | | set max=!m:~100,2! | | set text=%%a | | ) | | ) | | echo !text! | | pauseCOPY |
同样的算法稍加改动,日后最多可以兼容四千多位: | @echo off&setlocal enabledelayedexpansion | | for /l %%a in (1 1 5) do set a=!a!0987654321 | | for /l %%a in (0 1 4) do set b=%%a%%a%%a%%a%%a%%a%%a%%a%%a%%a!b! | | for /f "delims=" %%a in (a.txt) do ( | | set str=%%a | | set m=!str: =!!a! | | set n=!str: =!!b! | | if "1!n:~50,1!!m:~50,1!" gtr "1!max!" ( | | set max=!n:~50,1!!m:~50,1! | | set text=%%a | | ) | | ) | | echo !text! | | pauseCOPY |
|