int main()
{
int low1,up1,low2,up2
printf("输入第一个闭区间:")
scanf("%d,%d",&low1,&up1)
printf("输入第二个闭区间:")
scanf("%d,%d",&low2,&up2)
printf("交集:")
if(low1>up2 || low2>up1)
printf("空集\n")
else if(up1>=up2)
{
if(low1>low2)
printf("[%d,%d]",low1,up2)
else
printf("[%d,%d]",low2,up2)
}
else if(up2>up1)
{
if(low2>low1)
printf("[%d,%d]",low2,up1)
else
printf("[%d,%d]",low1,up1)
}
}
你的格式不对。应该分成两列,A列和B列A B
1 2
1 3
0 2
0 3
在A5单元格中输入公式:
=max(a1:a4)&"-"&min(b1:b4)
返回的结果是1-2,应该就是你要的交集区间吧?
用函数似乎可以解决,我帮你看看!
给你个VBA代码 ,适用方法简单说下 ,进入VBA编辑器,插入模块,复制代码进去,退回你的数据表格 然后运行代码即可!
Sub rr()
Dim i%, k%, s As String
For i = 2 To Range("b65536").End(xlUp).Row
For k = 2 To Range("b65536").End(xlUp).Row
If i <>k Then
If (Cells(k, 3) >Cells(i, 2) And Cells(i, 2) >Cells(k, 2)) Or (Cells(k, 3) >Cells(i, 3) And Cells(i, 3) >Cells(k, 2)) Or (Cells(k, 3) <Cells(i, 3) And Cells(i, 2) <Cells(k, 2)) Then
s = Cells(k, 1) &"," &s
End If
End If
Next
If Len(s) >0 Then
Cells(i, 4) = Left(s, Len(s) - 1)
Else
Cells(i, 4) = ""
End If
s = ""
Next
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)