求交集,并集,补集。想问一下大佬们为什么这个会超时
#include <stdio.h>#define MAX 10000
void found(int *a, int *b, int n, int m, char ch1, char ch2)
{
int i, j, count = 0;
for(i = 0; i < n; i++)
for(j = 0; j < m; j++)
{
if(a[i] == b[j])
count++;
}
if(count == m && m == n)
printf("A equals B\n");
else if(count == m)
printf("%c is a proper subset of %c\n", ch2, ch1);
else if(count == 0)
printf("A and B are disjoint\n");
else
printf("I'm confused!\n");
}
int main()
{
int a[MAX], b[MAX], n, m, i;
while(1)
{
for(i = 0; i < MAX && getchar() != '\n'; i++)
scanf("%d", &a[i]);
n = i;
for(i = 0; i < MAX && getchar() != '\n'; i++)
scanf("%d", &b[i]);
m = i;
if(n >= m)
found(a, b, n, m, 'A', 'B');
else
found(b, a, m, n, 'B', 'A');
}
return 0;
}