-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path22821:Oil Deposits
51 lines (48 loc) · 1.42 KB
/
22821:Oil Deposits
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
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, OCaml, VB, Perl, Swift, Prolog, Javascript, Pascal, COBOL, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
#include<iostream>
#include<vector>
using namespace std;
char mp[105][105];
int visited[105][105]={0};
int r,c;
void dfs(int i,int j){
if(i<0 || i>=r || j<0 || j>=c || visited[i][j]==1 || mp[i][j]=='*'){ //這個是要用“反”條件,如果是錯誤的條件就一直return,直到可行的條件就會執行下去
return;
}
visited[i][j]=1;
dfs(i-1,j-1);
dfs(i-1,j);
dfs(i-1,j+1);
dfs(i,j+1);
dfs(i+1,j+1);
dfs(i+1,j);
dfs(i+1,j-1);
dfs(i,j-1);
}
int main()
{
while(cin>>r>>c && r>0 && c>0){
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
cin>>mp[i][j];
visited[i][j]=0;
}
}
int count=0;
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
if(mp[i][j]=='@' && visited[i][j]==0){
dfs(i,j); //要記得是 dfs() 不是 dfs[]
count++;
}
}
}
cout<<count<<endl;
}
}