2024年4月19日发(作者:)
易语言交集并集补集源码
以下是易语言实现交集、并集、补集的代码示例:
```
// 交集
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
```
注意:以上代码示例只针对字符串进行了操作,如果要对其他
类型的集合进行操作,需要根据具体情况进行修改。
发布者:admin,转转请注明出处:http://www.yc00.com/web/1713460684a2253387.html
评论列表(0条)