还没来得及测试,也不知道对不对
省略读入文件,默认读入array[200][200]中
C语言编写
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(void)
{
srand((unsigned int)time(NULL));
int array[200][200];
int choose_1 = rand() % 199 + 1;
int a = sizeof(array[choose_1]) / sizeof(int);
int choose_2 = rand() % (a - 1) + 1;
int b = sizeof(array[choose_2]) / sizeof(int);
int flag = 0;
int count = 0;
while (1)
{
for (int i = 0; i < 199; i++)
{
if (array[i][0] != 0)
count++;
}
if (count <= 1) break;
count = 0;
for (int i = 0; i < b; i++)
{
int judge = 0;
for (int j = 0; j < a; j++)
{
if (array[choose_1][j] == array[choose_2][i] )
{
judge = 1;
break;
}
}
if (array[choose_2][i] == choose_1)
judge = 1;
if (!judge)
{
array[choose_1][a + flag] = array[choose_2][i];
flag++;
}
}
flag = 0;
for (int i = 0; i < 200; i++)
array[choose_2][i] = 0;
}
for (int i = 0; i < 199; i++)
{
if (array[i][0] != 0)
printf("%d", sizeof(array[i]) / sizeof(int) - 1);
}
}