forked from krish-ag/HacktoberFest22-Repo-DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Magical_grid_2D_matrix_problem.cpp
58 lines (54 loc) · 1.26 KB
/
Magical_grid_2D_matrix_problem.cpp
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
#include<bits/stdc++.h>
using namespace std;
void magical_park(char arr[1000][1000],int row,int col,int threshold_strength,int initial_strength) {
//person can get out of the park
bool success = true;
for(int i = 0;i<row;i++) {
for(int j = 0;j<col;j++) {
char ch = arr[i][j];
if(initial_strength < threshold_strength) {
success = false;
break;
}
if(ch == '*') {
initial_strength+=5;
}
else if(ch == '.') {
initial_strength-=2;
}
else {
break;
}
//we will loose 1 point when we move right except for the last column
if(j != col-1) {
initial_strength-=1;
}
}
}
if(success) {
cout<<"yes"<<endl;
cout<<initial_strength<<endl;
}
else {
cout<<"No"<<endl;
}
}
int main() {
char matrix_grid[1000][1000] = {
{'.','.','*','.'},
{'.','#','.','.'},
{'*','*','.','.'},
{'.','#','*','*'}
};
int row,cols,threshold_strength,initial_strength;
cout<<"enter row : ";
cin>>row;
cout<<"enter cols : ";
cin>>cols;
cout<<"enter threshold_strength : ";
cin>>threshold_strength;
cout<<"enter initial strength : ";
cin>>initial_strength;
magical_park(matrix_grid,row,cols,threshold_strength,initial_strength);
return 0;
}