language: C++ (gcc-4.3.4)
date: 104 days 0 hours ago
link:
visibility: public
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include<stdio.h>
#include<iostream>
#include<ctype.h>
using namespace std;
int loc[21][21],flag[21][21],res;
void func (int x,int y,int w,int h)
{
    //cout<<"yes\n";
    if(x>=w || x<0)
    return;
    if(y>=h || y<0)
    return;
    if(flag[y][x]==1)
    return;
    if((y+1)<h && loc[y+1][x]==1)
    {
        res++;
        func(x,y+1,w,h);
    }
    if(y-1>=0 && loc[y-1][x]==1)
    {
        res++;
        func(x,y-1,w,h);
    }
    if((x+1)<w && loc[y][x+1]==1)
    {
        res++;
        func(x+1,y,w,h);
    }
    if((x-1)>=0 && loc[y][x-1]==1)
    {
        res++;
        func(x-1,y,w,h);
    }
    flag[y][x]=1;
    return;
}
int main()
{
    int t,i,x,y,posx,posy,w,h,laa;
    char m;
    cin>>t;
    for(i=1;i<=t;i++)
    {
        cin>>w>>h;
        int res=0;
        for(y=0;y<h;y++)
        {
            for(x=0;x<w;x++)
            {
                m=getchar();
                laa=(int)m;
                while(isspace(laa))
                {
                      m=getchar();
                      laa=(int)m;
                }
                //cout<<"yes"<<m<<"\n";
                if(m=='.')
                {
                loc[y][x]=1;
                flag[y][x]=0;
                }
                if(m=='#')
                {
                loc[y][x]=0;
                flag[y][x]=0;
                }
                if(m=='@')
                {
                    loc[y][x]=1;
                    //cout<<"yes";
                    flag[y][x]=0;
                    posx=x;
                    posy=y;
                    res=1;
                    //cout<<"res="<<res;
                }
 
            }
            }
 
        if(res==1){
                //cout<<"yes";
            func(posx,posy,w,h);
            }
        cout<<"Case "<<i<<"="<<res<<"\n";
    }
    return 0;
}
 
  • upload with new input
  • result: Runtime error     time: 0.02s    memory: 10784 kB     signal: 11 (SIGSEGV)

    4
    
    6 9
    
    ....#.
    
    .....#
    
    ......
    
    ......
    
    ......
    
    ......
    
    ......
    
    #@...#
    
    .#..#.
    
    11 9
    
    .#.........
    
    .#.#######.
    
    .#.#.....#.
    
    .#.#.###.#.
    
    .#.#..@#.#.
    
    .#.#####.#.
    
    .#.......#.
    
    .#########.
    
    ...........
    
    11 6
    
    ..#..#..#..
    
    ..#..#..#..
    
    ..#..#..###
    
    ..#..#..#@.
    
    ..#..#..#..
    
    ..#..#..#..
    
    7 7
    
    ..#.#..
    
    ..#.#..
    
    ###.###
    
    ...@...
    
    ###.###
    
    ..#.#..
    
    ..#.#..