这题我的代码90分
不知道哪里错了awa
大佬们救救孩子吧!!!
我打的代码:
#include <bits/stdc++.h>
using namespace std;
const int N=22,M=22;
int n,m,a[N][M],x,y,ans;
int st[N][M];
int ss(){
if(a[y+1][x]==0&&y+1<n&&!st[y+1][x]){
st[y+1][x]=1;
ans++;
y++;
ss();
y--;
}
if(a[y-1][x]==0&&y-1>=0&&!st[y-1][x]){
st[y-1][x]=1;
ans++;
y--;
ss();
y++;
}
if(a[y][x+1]==0&&x+1<m&&!st[y][x+1]){
st[y][x+1]=1;
ans++;
x++;
ss();
x--;
}
if(a[y][x-1]==0&&x-1>=0&&!st[y][x-1]){
st[y][x-1]=1;
ans++;
x--;
ss();
x++;
}
}
int main(){
string str;
while(1){
ans=0;
memset(a,0,sizeof a);
memset(st,0,sizeof st);
cin >>m>>n;
if(!m)break;
getline(cin,str);
for(int i=0;i<n;i++){
getline(cin,str);
for(int j=0;j<m;j++){
if(str[j]=='@')x=j,y=i;
if(str[j]=='.'||str[j]=='@')a[i][j]=0;
else a[i][j]=1;
}
}
ss();
cout <<ans<<endl;
}
return 0;
}