just for fun! 没什么好讲的,直接上代码以及程序结果。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<Windows.h>
#include<time.h>
#include<string.h>
#define ROW 5
#define COL 5
#define LEN 9
void InitMap(char tic[][COL], int x, int y)
{
int i = 0, j = 0,k = 0;
char arr[LEN] = "123456780";
int brr[LEN] = { 0 };
for (i = 1; i < x-1; i++)
{
for (j = 1; j < y-1; j++)
{
while (1)
{
k = rand() % LEN;
brr[k] += 1;
if (brr[k] == 1)
break;
}
tic[i][j] = arr[k];
}
}
for (i = 0; i < x; i++)
{
for (j = 0; j < y; j++)
{
if (i == 0 || i == ROW - 1 || j == 0 || j == COL - 1)
tic[i][j] = '9';
}
}
}
void Display(char tic[][COL], int x, int y)
{
int i = 0, j = 0;
for (i = 1; i < x-1; i++)
{
for (j