交集处理,在并集处理的模版改为交集的处理而已,没有多少变化。- @echo off&setlocal enabledelayedexpansion
- set A={1,[3,6],10,[20,30],[32,60],[200,3000],5000,[6000,8002],9000,9500}
- set B={2,5,31,[45,49],55,[300,500],[8000,9000],9500}
- ::为了处理更多的情况,在楼主的例子上加了一些数据
-
-
- ::拆分A 和 B的数据集
- set/a n=0,m=0
-
- set Av=!a:[=]!
- set Av=!Av:]="!
-
- for %%a in (%Av:~1,-1%) do (
- set a!n!=%%~a
- set/a n+=1
- )
-
- set Bv=!B:[=]!
- set Bv=!Bv:]="!
-
-
- for %%a in (%Bv:~1,-1%) do (
- set B!m!=%%~a
- set/a m+=1
- )
-
-
- ::设置上限
- set /a A!n!=2000000000
- set /a B!m!=2000000000
-
-
- ::根据a和b总项数来确定循环次,根据交集规则,进行判断重组
- set/a mn=m+n,n=0,m=0
- for /l %%a in (0,1,!mn!) do (
- for /f "tokens=1,2" %%m in ("!m! !n!") do (
- for /f "delims=," %%x in ("!A%%n!") do (
- for /f "delims=," %%o in ("!B%%m!") do (
-
- if %%x gtr %%o (set var=!B%%m!&set cur=m) else (set var=!A%%n!&set cur=n)
-
- for /f "tokens=1,2 delims=," %%1 in ("!var!,!var!") do (
- if !end! geq %%1 (
- if !end! geq %%2 (
- if %%1 equ %%2 (set aNb=!aNb!,%%1) else (set aNb=!aNb!,[%%1,%%2])
- ) else (
- if %%1 equ !end! (set aNb=!aNb!,%%1) else (set aNb=!aNb!,[%%1,!end!])
- )
- )
- if !end! lss %%2 set ben=%%1&set end=%%2
-
- )))
-
- set /a !cur!=!cur!+1
- )
- )
-
- echo;交集计算:
- echo;aNb={!aNb:~1!}
-
- pause
复制代码
|