#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void Stuffboard(int arr[3][3])
{
arr[0][0] = 1;
arr[1][1] = 1;
while (1)
{
arr[0][1] = rand() % 4;
arr[0][2] = rand() % 4;
arr[1][2] = rand() % 4;
if (arr[0][1] + arr[0][2] + arr[1][2] == 8 && arr[0][0] + arr[0][1] + arr[0][2] == 6&&arr[0][2]+arr[1][2]!=6)
break;
}
while (1)
{
arr[2][2] = rand() % 4;
arr[2][1] = rand() % 4;
if (arr[0][1] + arr[1][1] + arr[2][1] == 6 && arr[0][2] + arr[1][2] + arr[2][2] == 6)
break;
}
while (1)
{
arr[1][0] = rand() % 4;
arr[2][0] = rand() % 4;
if (arr[1][0] + arr[2][0] == 5 && arr[2][0] + arr[2][1] + arr[2][2] == 6)
break;
}
}
void DisPlayboard(int arr[3][3])
{
for (int i = 0; i < 3; i++) {
printf(" %d | %d | %d \n", arr[i][0], arr[i][1], arr[i][2]);
if (i < 2)
printf("---|---|---\n");
}
}
int main()
{
srand((unsigned int)time(NULL));//设置随机数的生成起点
int arr[3][3] = { 0 };
Stuffboard(arr);
DisPlayboard(arr);
return 0;
}
实验报告2
最新推荐文章于 2024-11-01 17:00:11 发布