前面排序都一样 后面判断稍不同- @echo off&setlocal enabledelayedexpansion
- set "str=1 2 55 3 4 5 1 7 8 9"
- for %%i in (!str!) do (
- if not defined .%%i (
- set /a n+=1
- set "_!n!=%%i"&set .%%i=a
- ))
- set /a m=n-1
- for /l %%i in (1,1,!m!) do (
- set /a e=%%i+1
- for /l %%j in (!e!,1,!n!) do (
- if !_%%i! gtr !_%%j! set/a _%%j=!_%%i!,_%%i=!_%%j!
- )
- )
- for /l %%i in (1,1,!n!) do (
- if !s1! equ !_%%i! (
- set/a s1-=1
- if defined ..!s1! (set var=!var! !_%%i!)else set var=!var! !s1! !_%%i!
- set ..!_%%i!=.
- )
- set/a s1=_%%i+1
- )
- echo!var!
- pause
复制代码
- @echo off&setlocal enabledelayedexpansion
- set "str=2 2 12 3 4 5 11 7 8 9"
- for %%i in (!str!) do (
- if not defined .%%i (
- set /a n+=1
- set "_!n!=%%i"&set .%%i=a
- ))
- set /a m=n-1
- for /l %%i in (1,1,!m!) do (
- set /a e=%%i+1
- for /l %%j in (!e!,1,!n!) do (
- if !_%%i! gtr !_%%j! set/a _%%j=!_%%i!,_%%i=!_%%j!
- )
- )
- for /l %%i in (1,1,!n!) do (
- if not defined a1 (set/a a1=_%%i,m=1)else (
- set/a "an=a1+m-1"
- if !an! equ !_%%i! (
- if !m! equ 2 (set var=!var! !a1! !an!) else set var=!var! !an!
- ) else set/a a1=_%%i,m=1
- )
- set /a m+=1
- )
- echo!var!
- pause
复制代码
[ 本帖最后由 terse 于 2009-10-2 13:23 编辑 ] |