admin 管理员组

文章数量: 1087135


2024年4月30日发(作者:怎么用plot命令绘制函数图像)

易语言交集并集补集源码

以下是易语言实现交集、并集、补集的代码示例:

```

// 交集

strA = "12345"

strB = "34567"

intersect = ""

for i = 1 to len(strA)

char = left(strA, i, 1)

if instr(strB, char) <> 0 and instr(intersect, char) = 0 then

intersect = intersect + char

end if

next i

print intersect

// 并集

strA = "12345"

strB = "34567"

union = ""

for i = 1 to len(strA)

char = left(strA, i, 1)

if instr(union, char) = 0 then

union = union + char

end if

next i

for i = 1 to len(strB)

char = left(strB, i, 1)

if instr(union, char) = 0 then

union = union + char

end if

next i

print union

// 补集

strA = "12345"

strB = "34567"

complement = ""

for i = 1 to len(strA)

char = left(strA, i, 1)

if instr(strB, char) = 0 and instr(complement, char) = 0 then

complement = complement + char

end if

next i

print complement

```

注意:以上代码示例只针对字符串进行了操作,如果要对其他

类型的集合进行操作,需要根据具体情况进行修改。


本文标签: 进行 交集 示例 操作 代码