- @echo off
- setlocal EnableDelayedExpansion
- set txt=1.txt
- set __yiwuyun.txt=___yiwuyun.txt
- set "space= "
- set /a Number=50
- set /a maxNumber=!Number!-1
- set /a suzu.MaxRow=0
- for /l %%a in (0,1,!maxNumber!) do (
- if %%a lss 9 (
- set /a tempb=%%a+1
- set suzu0.%%a=0!tempb!
- ) else (
- set /a suzu0.%%a=%%a+1
- )
- )
- set /a suzu0.MaxCol=!maxNumber!
- for /f "delims=" %%a in ('type !txt!') do (
- set "string=%%a"
- set "s1="
- call :GetTokenTextNAndCount "^!string^!" "^!space^!"
- for /l %%c in (1,1,!tokenTextCount!) do (
- call :GetRowColInSuzu !suzu.MaxRow! !tokenText%%c!
- call :DeleteFromSuzu !rowInSuzu! !colInSuzu!
- if !rowInSuzu! equ !suzu.MaxRow! (
- set /a rowInSuzu+=1
- set /a suzu.MaxRow=!rowInSuzu!
- set suzu!suzu.MaxRow!.0=!tokenText%%c!
- set /a suzu!suzu.MaxRow!.MaxCol=0
- ) else (
- set /a rowInSuzu+=1
- call :AddToSuzu !rowInSuzu! !tokenText%%c!
- )
- )
- )
- call :PrintSuzu
- pause
- exit /b 0
-
-
- :PrintSuzu
- for /l %%a in (0,1,!suzu.MaxRow!) do (
- for /l %%b in (0,1,!suzu%%a.MaxCol!) do (
- if %%b equ !suzu%%a.MaxCol! (
- set "s=!s!!suzu%%a.%%b!"
- ) else (
- set "s=!s!!suzu%%a.%%b! "
- )
- )
- echo.%%a: !s!
- set "s="
- )
- exit /b 0
-
-
- :GetRowColInSuzu
- for /l %%a in (0,1,%1) do (
- for /l %%b in (0,1,!suzu%%a.MaxCol!) do (
- if "!suzu%%a.%%b!"=="%2" (
- set /a rowInSuzu=%%a
- set /a colInSuzu=%%b
- goto endGetRowColInSuzu
- )
- )
- )
- :endGetRowColInSuzu
- exit /b 0
-
-
- :DeleteFromSuzu
- if %2 equ !suzu%1.MaxCol! (
- set /a suzu%1.MaxCol-=1
- ) else (
- set /a nDeleteFromSuzu=!suzu%1.MaxCol!-1
- for /l %%a in (%2,1,!nDeleteFromSuzu!) do (
- set /a n=%%a+1
- for /l %%b in (!n!,1,!n!) do set suzu%1.%%a=!suzu%1.%%b!
- )
- set /a suzu%1.MaxCol=!nDeleteFromSuzu!
- )
- exit /b 0
-
-
- :AddToSuzu
- set /a max=!suzu%1.MaxCol!
- if !max! equ -1 (
- set suzu%1.MaxCol=0
- set "suzu%1.0=%2"
- ) else (
- for /l %%a in (0,1,!max!) do (
- set /a p=%%a+1
- if "%2" lss "!suzu%1.%%a!" (
- set /a m=!suzu%1.MaxCol!+1
- for /l %%b in (!m!,-1,!p!) do (
- set /a k=%%b-1
- for /l %%c in (!k!,1,!k!) do set suzu%1.%%b=!suzu%1.%%c!
- )
- set suzu%1.%%a=%2
- set /a suzu%1.MaxCol=!m!
- goto end
- ) else (
- if "%%a"=="!max!" (
- set /a suzu%1.MaxCol+=1
- set suzu%1.!suzu%1.MaxCol!=%2
- )
- )
- )
- )
- :end
- exit /b 0
-
-
-
- :GetStringLength
- setlocal
- set string=!string!
- set /a n=0
- :startGetStringLength
- if not "!string!"=="" (
- set string=!string:~1!
- set /a n=!n!+1
- goto startGetStringLength
- )
- set /a stringLength=!n!
- endlocal&set stringLength=%stringLength%
- exit /b 0
-
-
- :GetTokenPlaceNAndCount
- setlocal
- set "string=%~1"
- set "secondParameter=%~2"
- call :GetStringLength
- set /a nGetTokenPlaceNAndCount=!stringLength!-1
- set /a nToken=1
- set /a tokenPlace0=-1
- for /l %%a in (0,1,!nGetTokenPlaceNAndCount!) do (
- if "!string:~%%a,1!"=="!secondParameter!" (
- set /a tokenPlace!nToken!=%%a
- set /a nToken+=1
- )
- )
- set /a tokenPlace!nToken!=!stringLength!
- set /a tokenCount=!nToken!-1
- type nul>!__yiwuyun.txt!
- for /l %%a in (0,1,!nToken!) do (
- echo set /a tokenPlace%%a=!tokenPlace%%a!>>!__yiwuyun.txt!
- )
- echo set /a tokenCount=!tokenCount!>>!__yiwuyun.txt!
- endlocal
- for /f "tokens=1 delims=" %%a in ('type !__yiwuyun.txt!') do (
- %%a
- )
- if exist !__yiwuyun.txt! del !__yiwuyun.txt!
- exit /b 0
-
-
- :GetTokenTextNAndCount
- set "string=%~1"
- set "___secondParameter=%~2"
- call :GetTokenPlaceNAndCount "^!string^!" "^!___secondParameter^!"
- set /a ___next=0
- set /a tokenTextCount=!tokenCount!+1
- set /a ___n=0
- :startGetTokenTextNAndCount
- set /a ___beforePlace=!tokenPlace%___next%!
- set /a ___first=!___beforePlace!+1
- set /a ___next=!___next!+1
- set /a ___afterPlace=!tokenPlace%___next%!
- set /a ___second=!___afterPlace!-!___beforePlace!-1
- set /a ___n=!___n!+1
- if "!string!"=="" (
- set "tokenText!___n!="
- ) else (
- set tokenText!___n!=!string:~%___first%,%___second%!
- )
- if !___n! lss !tokenTextCount! goto startGetTokenTextNAndCount
- exit /b 0
复制代码
|