poj1979广搜c语言

来源:互联网 发布:php函数list 编辑:程序博客网 时间:2024/05/10 00:14
坑了,写程序的时候倒数第二个花括号把return 0;给我括起来了,程序一次就结束了,吃了饭回来才顿悟了
#include<stdio.h>struct point{int hang,lie;int predecessor;}queue[402],p,visit_point;char brr[30][30],c;int head=0,tail=0,n,m;void enqueue(struct point p){    queue[tail++] = p;}struct point dequeue(void){    return queue[head++];}void visit(int hang, int lie){    visit_point.hang=hang;visit_point.lie=lie;visit_point.predecessor=head-1;    brr[hang][lie] = '#';    enqueue(visit_point);}int main(){int i,j;while(1){    scanf("%d%d",&n,&m);    if(m==0&&n==0)            break;scanf("%c",&c);for(i=0;i<m;i++)for(j=0;j<=n;j++){scanf("%c",&brr[i][j]);if(brr[i][j]=='@'){p.hang=i;p.lie=j;p.predecessor=1;}}        queue[0]=p;tail++;while(tail!=head)        {            p = dequeue();            if (p.lie+1 < n && brr[p.hang][p.lie+1] == '.')            visit(p.hang, p.lie+1);            if (p.hang+1 < m  && brr[p.hang+1][p.lie] == '.')            visit(p.hang+1, p.lie);            if (p.lie-1 >= 0  && brr[p.hang][p.lie-1] == '.')            visit(p.hang, p.lie-1);            if (p.hang-1 >= 0&& brr[p.hang-1][p.lie] == '.')            visit(p.hang-1, p.lie);        }        printf("%d\n",tail);        head=0;tail=0;}return 0;}

0 0