-
Notifications
You must be signed in to change notification settings - Fork 0
/
cakeminator.cpp
61 lines (55 loc) · 862 Bytes
/
cakeminator.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
59
60
#include<iostream>
#define MAX 10
using namespace std;
int main()
{
int r,c;
cin>>r>>c;
char matrix[r][c];
for(int i=0;i<r;++i) {
for(int j=0;j<c;++j) {
cin>>matrix[i][j];
}
}
//checking for rows
int total=0,sum=0;
for(int i=0;i<r;++i) {
sum=0;
for(int j=0;j<c;++j) {
if(matrix[i][j]=='S') {
for(int a=0;a<j;++a) matrix[i][a]='.';
sum=0;
break;
}
else {
if(matrix[i][j]!='1') {
// cout<<i<<" "<<j<<endl;
sum+=1;
matrix[i][j]='1';
}
}
}
total+=sum;
}
//checking for columns
for(int j=0;j<c;++j) {
sum=0;
for(int i=0;i<r;++i) {
if(matrix[i][j]=='S') {
for(int a=0;a<i;++a) matrix[a][j]='.';
sum=0;
break;
}
else {
if(matrix[i][j]!='1') {
matrix[i][j]='1';
//cout<<i<<" "<<j<<endl;
sum+=1;
}
}
}
total+=sum;
}
cout<<total<<endl;
return 0;
}