-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRatinMaze.cpp
More file actions
79 lines (76 loc) · 1.13 KB
/
RatinMaze.cpp
File metadata and controls
79 lines (76 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// well two fruitful hours spent !!
#include <iostream>
using namespace std;
void inputArr(bool maze[][20],int n)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin>>maze[i][j];
}
}
}
void outputArr(bool maze[][20],int n)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cout<<maze[i][j]<<" ";
}
cout<<endl;
}
}
bool isPlace(bool maze[][20],int i,int j,int n)
{
if(i<n&&j<n&& maze[i][j]==true)
{
return true;
}
return false;
}
bool RatInAMaze(bool maze[][20],int i,int j,int n, bool ans[][20])
{
if(i==n-1&&j==n-1)
{
ans[n-1][n-1]=true;
return true;
}
if(isPlace(maze,i,j,n)==true)
{
ans[i][j]=true;
bool right= RatInAMaze(maze,i,j+1,n,ans);
bool down = RatInAMaze(maze,i+1,j,n,ans);
if(right==true)
{
return true;
}
if(down==true)
{
return true;
}
if(right==false && down == false)
{
ans[i][j]=false;
}
}
return false;
}
int main()
{
int n;
cin>>n;
bool maze[20][20],ans[20][20]={0};
inputArr(maze,n);
bool possible = RatInAMaze(maze,0,0,n,ans);
cout<<endl;
if(possible)
{
cout<<"yay"<<endl;
outputArr(ans,n);
}
else{
cout<<"No can dos will baby doll !";
}
}