原帖由 batman 于 2009-8-26 19:21 发表
@echo off&setlocal enabledelayedexpansion
set "str=afdjg do men contgfirfmck song putint"
set /a max=8190,min=0
for /l %%a in (1,1,14) do (
set /a "num=(max+min)/2"
for /f "delims=" ...
@ECHO OFF & SETLOCAL ENABLEDELAYEDEXPANSION
IF %1*==* GOTO :EOF
ECHO 计算 %1 的长度
SET L=%~1
SET X=0
IF "%L%"=="" GOTO END
ECHO 假设这个变量最长为 8190,二分法判断序列如下:
SET /A N=0,M=8190
FOR /L %%C IN (1,1,14) DO (
SET /A X0=%X%
SET /A "X=(!M!+!N!)/2"
ECHO !X!;若小则!X!~!M!;若大则!N!~!X!。
FOR /F %%D IN ("!X!") DO IF "!L:~%%D!" EQU "" (SET /A M=!X! ) ELSE (SET /A N=!X!)
)
:END
SET /A X+=1
ECHO.
ECHO.
ECHO 计算结果为%X%字符 &PAUSE
@ECHO OFF & setlocal enabledelayedexpansion
ECHO %1
SET NAME=%~1
SET /A M=0
OOP
SET /A M=%M%+1
FOR /F "DELIMS=" %%C IN ("!M!") DO IF "!NAME:~%%C,1!" EQU "" GOTO END
GOTO LOOP
:END
ECHO %M% 个字符。
PAUSE