第二题20分钟查不出错来,竟然坑在了字符串读入上,真服了~~
scanf(“%s”, str[i] + 1)是为了从下标为1读入!!记住呜呜!!
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
const int N = 20;
bool st[N][N][N];
int k,n,m;
char g[N][N][N];
int a,b;
struct Point
{
int x,y,z;
};
int bfs(Point start,int &ans)
{
queue<Point>q;
q.push(start);
st[start.x][start.y][start.z] = true;
while (q.size())
{
Point t=q.front();
q.pop();
int dx[6]={1,-1,0,0,0,0},dy[6]={0,0,1,-1,0,0},dz[6]={0,0,0,0,1,-1};
for (int i=0;i<6;i++)
{
int x=t.x+dx[i];
int y=t.y+dy[i];
int z=t.z+dz[i];
if (x<1||x>k||y<1||y>n||z<1||z>m) continue;
if (g[x][y][z]=='#') continue;
if (st[x][y][z]) continue;
ans++;
st[x][y][z]=true;
q.push({x,y,z});
}
}
}
int main()
{
cin>>k>>n>>m;
for (int i=1;i<=k;i++)
for (int j=1;j<=n;j++)
scanf("%s",g[i][j]+1); # g[i][j]+1 是为了下标为1读入!!
cin>>a>>b;
Point start = {1,a,b};
int ans = 1;
bfs(start,ans);
cout<<ans<<endl;
return 0;
}