本帖最后由 a20150604 于 2019-8-8 17:38 编辑
你要处理的文本存入 s.txt- @echo off & setlocal enabledelayedexpansion
- chcp 936
- mode 200,1000
- set LN=^
-
-
- echo;[!LN!]
-
- >tmp.txt cd.
-
- for /f "delims=" %%a in (s.txt) do (
- set "lin=%%a"
- set "lin=!lin: =!"
- echo !lin!
-
- call :strlen lin length
- echo !length!
-
- call :output lin length
- )
-
- >sorted.txt sort tmp.txt
- >info.txt cd.
- set "last_distinct_line="
- set /a "cnt_duplicate=0,times_per_line=1"
- for /f "delims=" %%a in (sorted.txt) do (
- if "%%a"=="!last_distinct_line!" (
- set /a "times_per_line+=1"
- if !times_per_line!==2 (
- set /a cnt_duplicate+=1
- )
- ) else (
- if "!last_distinct_line!" neq "" if !times_per_line! gtr 1 (
- echo;!cnt_duplicate!,!times_per_line!:!last_distinct_line!
- >>info.txt echo;!cnt_duplicate!,!times_per_line!:!last_distinct_line!
- )
- set "last_distinct_line=%%a"
- set /a "times_per_line=1"
- )
- )
- set cnt_duplicate
-
- pause
- exit
-
-
- :output
- setlocal enabledelayedexpansion
- set /a p=0
- :loop
- set "out="
- for /L %%i in (1 1 100) do (
- if !p! lss !%2! for %%p in (!p!) do set "out=!out!!%1:~%%p,1!!LN!"
- set /a p+=1
- )
- >>tmp.txt (echo;!out:~0,-1!)
- if !p! lss !%2! goto :loop
- endlocal
- exit /b
-
-
- :strlen <stringVarName> [retvar]
- :: 思路: 二分回溯联合查表法
- :: 说明: 所求字符串大小范围 0K ~ 8K;
- :: stringVarName ---- 存放字符串的变量名
- :: retvar ---- 接收字符长度的变量名
- setlocal enabledelayedexpansion
- set "$=!%1!#"
- set N=&for %%a in (4096 2048 1024 512 256 128 64 32 16)do if !$:~%%a!. NEQ . set/aN+=%%a&set $=!$:~%%a!
- set $=!$!fedcba9876543210&set/aN+=0x!$:~16,1!
- endlocal&If %2. neq . (set/a%2=%N%)else echo %N%
-
- exit /b
复制代码
|