简单C程序,迷宫

时间:2022-10-16 20:11:16
 #include<stdio.h>
#include <stdlib.h>
int visit(int, int);
int maze[][] =
{
{, , , , , , , , ,},
{, , , , , , , , ,},
{, , , , , , , , ,},
{, , , , , , , , ,},
{, , , , , , , , ,},
{, , , , , , , , ,},
{, , , , , , , , ,},
{, , , , , , , , ,},
{, , , , , , , , ,},
{, , , , , , , , , },
{, , , , , , , , , },
};
int startI = , startJ = ; // 入口
int endI = , endJ = ; // 出口
int success = ; int main(void) {
int i, j; printf("显示迷宫:\n");
for (i = ; i < ; i++) {
for (j = ; j < ; j++)
if (maze[i][j] == )
printf("■");
else
printf(" ");
printf("\n");
} if (visit(startI, startJ) == )
printf("\n沒有找到出口!\n");
else {
printf("\n显示路径:\n");
for (i = ; i < ; i++) {
for (j = ; j < ; j++) {
if (maze[i][j] == )
printf("■");
else if (maze[i][j] == )
printf("▲");
else
printf(" ");
}
printf("\n");
}
} return ;
} int visit(int i, int j) {
maze[i][j] = ; if (i == endI && j == endJ)
success = ; if (success != && maze[i][j + ] == ) visit(i, j + );
if (success != && maze[i + ][j] == ) visit(i + , j);
if (success != && maze[i][j - ] == ) visit(i, j - );
if (success != && maze[i - ][j] == ) visit(i - , j); if (success != )
maze[i][j] = ; return success;
}
 //参考.c
#include<iostream> using namespace std;
void strMatrix(int *a1, int **a2, int n);
void output(int **a2, int n);
int main()
{
int n, i, c, d;
cout << "How many numbers do you want to input:" << endl;
cin >> n;
int *arr1 = new int[n];
int **arr2 = new int*[n];
for (i = ; i < n; i++)
arr2[i] = new int[n];
cout << "Please input the numbers:" << endl;
for (i = ; i < n; i++)
cin >> arr1[i];
cout << "Please input the ralations:" << endl;
cin >> c;
cin >> d;
strMatrix(arr1, arr2, n);
output(arr2, n);
}
void strMatrix(int *a1, int **a2, int n)
{
for (int i = ; i < n; i++)
for (int j = ; j < n; j++)
{
if (a1[i] % a1[j] == )
a2[i][j] = ;
else
a2[i][j] = ;
}
}
void output(int **a2, int n)
{
for (int i = ; i < n; i++)
{
for (int j = ; j < n; j++)
cout << a2[i][j] << " ";
cout << endl;
}
} void zfx(int a[M][M], int n)
{
int i = , vale1 = , vale2 = ;/*vale1确定关系的自反性,vale2
判断关系的反自反性*/
while (i < n)
{
if (a[i][i] == ) vale2 = ;
else vale1 = ;
i++;
}
if (vale1 == ) printf("zfx\n");
if (vale2 == ) printf("fzfx\n");
if (!(vale1) && !(vale2)) printf("wzfxywfzfx\n");
}
void dcx(int a[M][M], int n)
{
int i, j, vale3 = , vale4 = ;/*vale3确定关系的对称性,vale4
判断关系的反对称性*/
for (i = ; i < n; i++)
for (j = ; j < i; j++)
if (a[i][j] == a[j][i])
vale4 = ;
else vale3 = ;
if (vale3 == ) printf("dcx\n");
if (vale4 == ) printf("fdcx\n");
if (!(vale3) && !(vale4)) printf("wdcx wfdcx\n");
} void cdx1(int a[M][M], int n)/*用MM ⊆2 算法来判断传递 性*/
{
int b[M][M], i, j, k, vale = ;
for (i = ; i < n; i++)
for (j = ; j < n; j++)
{
b[i][j] = ;
for (k = ; k < n; k++)
b[i][j] += a[i][k] * a[k][j];/*计算 2M */
}
for (i = ; i < n; i++)
for (j = ; j < n; j++)
if (b[i][j] != )
b[i][j] = ;
for (i = ; i < n; i++)
for (j = ; j < n; j++)
if (b[i][j] == )
if (a[i][j] != b[i][j])
vale = ;
if (vale)
printf("ycdx\n");
else
printf("wcdx\n");
}
void cdx2(int a[M][M], int n)/*用warshall算法来求传递闭
包数组b */
{
int b[M][M], i, j, k, vale = ;
for (i = ; i < n; i++)
for (j = ; j < n; j++)
b{ [i][j] = a[i][j];
for (k = ; k < n; k++)
i{ (f a[i][j] && (a[i][k] || a[j][k]))
b[i][k] = ;
}
}
for (i = ; i < n; i++) /* 判断数组a和b相等 */
for (j = ; j < n; j++)
(iaf[i][j] != b[i][j])
{
vale = ; break;
}
if (vale == ) printf("cdx\n");
else printf("wcdx\n");
}