本帖最后由 zm900612 于 2011-6-11 14:11 编辑
27# DAIC - [code]@echo off&setlocal enabledelayedexpansion
- set min=18100101
- set max=20100101
- echo %time%
-
- for /l %%a in (31 -1 1) do (
- set tmp=0%%a
- set md=!md! !tmp:~-2!
- )
- ::先将个位数转换为0开头,避免在循环中计算
-
- set /a y1=%min:~0,-4%,y2=%max:~0,-4%,m1=1%min:~-4,2%-100,m2=1%max:~-4,2%-100,d1=1%min:~-2%-100,d2=1%max:~-2%-100,s1=~-m1*31+d1-1,s2=(13-m2)*31-d2
- ::进行一些计算,这里的s1和s2是最重要的两个值,直接关系到后文“砍头去尾”的算法
-
- (for /l %%a in (%y2% -1 %y1%) do (
- set /a "1/(%%a%%3200)"||set pr=!pr! %%a0229
- for %%b in (%md:*13 =%) do (
- for %%c in (%md%) do (
- echo %%a-%%b-%%c
- )
- )
- ))>tmp 2>nul
- ::简单输出所有可能正确的日期
-
- if %s2% gtr 0 set skip1="skip=%s2%"
- (for /f %skip1% %%a in (tmp) do echo %%a)>tmp2
- sort tmp2 >tmp
- if %s1% gtr 0 set skip2="skip=%s1%"
- (for /f %skip2% %%a in (tmp) do echo %%a)>tmp2
- findstr /e "[^2]-.. 12-.. 02-[0-1]. 02-2[0-8] [02468][048]-02-29 [13579][26]-02-29" tmp2|findstr /ve "0[2469]-31 02-30 11-31 [02468][048]00-02-29 [13579][26]00-02-29 %pr%">pr.txt
- ::整个代码最关键的部分,先用more+sort砍头去尾,削除不在要求之内的日期,再用findstr双向筛选排除非法日期
-
- echo %time%
- pause
复制代码 少于17年的话,用这个更快- @echo off&setlocal enabledelayedexpansion
- set min=18100101
- set max=20100101
- echo %time%
-
- for /l %%a in (31 -1 1) do (
- set tmp=0%%a
- set md=!md! !tmp:~-2!
- )
- ::先将个位数转换为0开头,避免在循环中计算
-
- set /a y1=%min:~0,-4%,y2=%max:~0,-4%,m1=1%min:~-4,2%-100,m2=1%max:~-4,2%-100,d1=1%min:~-2%-100,d2=1%max:~-2%-100,s1=~-m1*31+d1-1,s2=(13-m2)*31-d2
- ::进行一些计算,这里的s1和s2是最重要的两个值,直接关系到后文“砍头去尾”的算法
-
- (for /l %%a in (%y2% -1 %y1%) do (
- set /a "1/(%%a%%3200)"||set pr=!pr! %%a0229
- for %%b in (%md:*13 =%) do (
- for %%c in (%md%) do (
- echo %%a-%%b-%%c
- )
- )
- ))>tmp 2>nul
- ::简单输出所有可能正确的日期
-
- more +%s2% tmp|sort|more +%s1%|findstr /e "[^2]-.. 12.. 0-2[0-1]. 02-2[0-8] [02468][048]-02-29 [13579][26]-02-29"|findstr /ve "0[2469]-31 02-30 11-31 [02468][048]00-02-29 [13579][26]00-02-29 %pr%">pr.txt
- ::整个代码最关键的部分,先用more+sort砍头去尾,削除不在要求之内的日期,再用findstr双向筛选排除非法日期
-
- echo %time%
- pause
复制代码
|