本帖最后由 dengyuli 于 2014-11-23 14:05 编辑
代码如下:- @echo off
- setlocal enabledelayedexpansion
- if "%1"=="/?" goto:usage
- if "%1"=="" goto:usage
- if "%1"=="/add" goto:add
- if "%1"=="/clr" goto:clr
- goto:calculate
- :add
- set ctr=0
- set "%3=%~2"
- set ctr%3=0
- for %%a in (%~2) do (
- set /a ctr+=1
- set /a ctr%3+=1
- for /l %%b in (!ctr!,1,!ctr!) do (
- set %3%%b=%%a
- )
- )
- for /l %%a in (1,1,!ctr!) do (
- echo %3%%a^=!%3%%a!>>"!temp!\mash_vars"
- )
- echo %3^=!%3!>>"!temp!\mash_vars"
- echo ctr%3^=!ctr%3!>>"!temp!\mash_vars"
- endlocal
- for /f "delims=` tokens=* usebackq eol=" %%a in ("%temp%\mash_vars") do (
- set "%%a"
- )
- goto:eof
- :calculate
- if "%2"=="u" goto:unionset
- if "%2"=="n" goto:intsec
- if "%1"=="c" goto:compset
- if "%2"=="subset" goto:subset
- if "%2"=="prosub" goto:prosub
- goto:err
- :unionset
- for /f "delims=` tokens=* eol=" %%a in ('type "%temp%\mash_vars"') do (
- set "%%a"
- )
- set asd=0
- for /l %%a in (1,1,!ctr%1!) do (
- set %4%%a=!%1%%a!
- )
- set ctr=0
- rem ------------------he bing kai shi------------------
- set /a "cetac=!ctr%1!+1"
- set /a "ctr%4=!ctr%1!+!ctr%3!"
- for /l %%a in (!cetac!,1,!ctr%4!) do (
- set /a ctr+=1
- for /l %%b in (!ctr!,1,!ctr!) do (
- set "%4%%a=!%3%%b!"
- )
- )
- for /l %%a in (1,1,!ctr%4!) do (
- set /a asd=%%a+1
- for /l %%b in (!asd!,1,!ctr%4!) do (
- if "!%4%%a!"=="!%4%%b!" set "%4%%b="
- )
- )
- rem ------------------he bing jie shu-------------------
- set "%4=cskwofuniset"
- set /a "ctr%4=!ctr%1!+!ctr%3!"
- for /l %%a in (1,1,!ctr%4!) do (
- set "%4=!%4!,!%4%%a!"
- )
- set "t=!%4!"
- set "%4=!t:cskwofuniset,=!"
- set "t=!%4!"
- set "%4=!t:,,=,!"
- set "t=!%4!"
- set "%4=!t:,,=,!"
- set "t=!%4!"
- if "!t:~-1!"=="," set %4=!t:~0,-1!
- set "t=!%4!"
- set "%4=!t: =!"
- for /l %%a in (1,1,!ctr%4!) do (
- echo %4%%a=!%4%%a!>>"!temp!\mash_vars"
- )
- echo %4^=!%4!>>"!temp!\mash_vars"
- endlocal
- for /f "delims=` tokens=* usebackq eol=" %%a in ("%temp%\mash_vars") do (
- set "%%a"
- )
- goto:eof
- :intsec
- for /f "delims=` tokens=* usebackq eol=" %%a in ("!temp!\mash_vars") do (
- set "%%a"
- )
- set def=0
- for /l %%a in (1,1,!ctr%1!) do (
- for /l %%b in (1,1,!ctr%3!) do (
- if "!%1%%a!"=="!%3%%b!" (
- set /a def+=1
- for /l %%c in (!def!,1,!def!) do (
- set "%4%%c=!%1%%a!"
- )
- ) else (
- break
- )
- )
- )
- set %4=cskwofintsec
- set ctr%4=!def!
- for /l %%a in (1,1,!def!) do (
- set "%4=!%4!,!%4%%a!"
- )
- set t=!%4!
- set %4=!t:cskwofintsec,=!
- set t=!%4!
- set %4=!t: =!
- echo %4=!%4!>>"!temp!\mash_vars"
- for /l %%a in (1,1,!ctr%4!) do (
- echo %4%%a=!%4%%a!>>"!temp!\mash_vars"
- )
- endlocal
- for /f "delims=` tokens=* usebackq eol=" %%a in ("%temp%\mash_vars") do (
- set "%%a"
- )
- goto:eof
- :compset
- for /f "delims=` tokens=* usebackq eol=" %%a in ("!temp!\mash_vars") do (
- set "%%a"
- )
- for /l %%a in (1,1,!ctr%2!) do (
- set "%4%%a=!%2%%a!"
- )
- for /l %%a in (1,1,!ctr%3!) do (
- for /l %%b in (1,1,!ctr%2!) do (
- if "!%3%%a!"=="!%2%%b!" set "%4%%b="
- )
- )
- set %4=cskwofcompset
- for /l %%a in (1,1,!ctr%2!) do (
- set "%4=!%4!,!%4%%a!"
- )
- set /a ctr%4=!ctr%2!-!ctr%3!
- set "t=!%4!"
- for /l %%a in (1,1,10) do (
- set "%4=!t:,,=,!"
- set "t=!%4!"
- )
- set %4=!t: =!
- set t=!%4!
- if "!t:~-1!"=="," set %4=!t:~0,-1!
- set t=!%4!
- set %4=!t:cskwofcompset,=!
- echo %4=!%4!>>"!temp!\mash_vars"
- for /l %%a in (1,1,!ctr%4!) do (
- echo %4%%a=!%4%%a!>>"!temp!\mash_vars"
- )
- echo ctr%4=!ctr%4!>>"!temp!\mash_vars"
- endlocal
- for /f "delims=` tokens=* usebackq eol=" %%a in ("%temp%\mash_vars") do (
- set "%%a"
- )
- goto:eof
- :subset
- for /f "delims=` tokens=* usebackq eol=" %%a in ("!temp!\mash_vars") do (
- set "%%a"
- )
- set ctr=0
- for /l %%a in (1,1,!ctr%1!) do (
- for /l %%b in (1,1,!ctr%3!) do (
- if "!%1%%a!"=="!%3%%b!" set /a ctr+=1
- )
- )
- set t=!ctr!
- set u=!ctr%1!
- set ctr=!t: =!
- set ctr%1=!u: =!
- if !ctr!==!ctr%1! (
- set "result_%1sub%3=true"
- ) else (
- set "result_%1sub%3=false"
- )
- echo result_%1sub%3=!result_%1sub%3!>>"!temp!\mash_vars"
- endlocal
- for /f "delims=` tokens=* usebackq eol=" %%a in ("%temp%\mash_vars") do (
- set "%%a"
- )
- goto:eof
- :prosub
- for /f "delims=` tokens=* usebackq eol=" %%a in ("!temp!\mash_vars") do (
- set "%%a"
- )
- set ctr=0
- for /l %%a in (1,1,!ctr%1!) do (
- for /l %%b in (1,1,!ctr%3!) do (
- if "!%1%%a!"=="!%3%%b!" set /a ctr+=1
- )
- )
- set t=!ctr!
- set u=!ctr%1!
- set v=!ctr%3!
- set ctr=!t: =!
- set ctr%1=!u: =!
- set ctr%3=!v: =!
- if !ctr!==!ctr%1! (
- if !ctr%1! lss !ctr%3! (
- set result_%1pro%3=true
- ) else (
- set result_%1pro%3=false
- )
- ) else (
- set result_%1pro%3=false
- )
- echo result_%1pro%3=!result_%1pro%3!>>"!temp!\mash_vars"
- endlocal
- for /f "delims=` tokens=* usebackq eol=" %%a in ("%temp%\mash_vars") do (
- set "%%a"
- )
- goto:eof
- :clr
- del /f /q "!temp!\mash_vars" >nul
- goto:eof
- :usage
- echo=
- echo %~nx0——集合运算器
- echo=
- echo 用法:%~nx0 ^/add [集合元素] [集合名称]
- echo %~nx0 [集合名称1] [subset^|prosub] [集合名称2]
- echo %~nx0 [集合名称1] [u^|n] [集合名称2] [集合名称3]
- echo %~nx0 c [集合名称1] [集合名称2] [集合名称3]
- echo %~nx0 ^/clr
- echo=
- echo ^/add 添加一个集合,集合中各元素之间用英文逗号隔开,整个集合用
- echo 双引号括起来,集合名称不能为以下的任意一个:
- echo subset prosub u n c t v
- echo=
- echo ^/clr 清除所有的集合,当您退出程序之前,您应该使用此选项,
- echo 否则下次程序启动时,上一次所添加的集合仍然可用,这
- echo 可能会造成不可预料的错误!
- echo=
- echo 各运算符的含义如下:
- echo=
- echo subset 判断前者是否是后者的子集,若是,则将变量
- echo result_[集合名称1]sub[集合名称2] 的值设为
- echo true,否则设为false
- pause>nul
- echo=
- echo prosub 判断前者是否是后者的真子集,若是,则将变量
- echo result_[集合名称1]pro[集合名称2] 的值设为
- echo true,否则设为false
- echo=
- echo u 求两个集合的并集,并添加[集合名称3],[集合名称3]
- echo 中的元素是计算结果。
- echo=
- echo n 求两个集合的交集,并添加[集合名称3],[集合名称3]
- echo 中的元素是计算结果。
- echo=
- echo c 求两个集合的补集,并添加[集合名称3],[集合名称3]
- echo 中的元素是计算结果。
- echo=
- echo 若要查看集合,则要输入echo [变量名],变量名为要查看的
- echo 集合名称
- echo=
- goto:eof
复制代码 不知道在我之前有没有人做过这个? |