UVa 11244 counting stars ( 搜索 BFS)

这道题,我承认特别水,但是我提交了第四次才过

各种错误,前两次是测试数据的输出没有注释掉,后一次是把数据看错了

这样的题不应该这么慢,一次过是很正常的,因为太简单了,这样的错误千万别犯了

代码:

#include <cstdio>
#include <cstring>

const int N = 150;
int r, c;
char g[N][N];

int main()
{
    while ( scanf("%d%d", &r, &c ) != EOF && !( !r && !c ) ) {
        getchar();
        int num = 0;
        for ( int i = 1; i <= r; getchar(), ++i ) 
            for ( int j = 1; j <= c; ++j ) 
                scanf("%c", &g[i][j]);
        for ( int i = 1; i <= r; ++i )
            for ( int j = 1; j <= c; ++j ) {
                if ( g[i][j] == '*' ) {
                    if ( i > 1 && g[i-1][j] == '*' ) continue;
                    if ( j > 1 && g[i][j-1] == '*' ) continue;
                    if ( i < r && g[i+1][j] == '*' ) continue;
                    if ( j < c && g[i][j+1] == '*' ) continue;
                    if ( j > 1 && i > 1 && g[i-1][j-1] == '*' ) continue;
                    if ( j < c && i < r && g[i+1][j+1] == '*' ) continue;
                    if ( j > 1 && i < r && g[i+1][j-1] == '*' ) continue;
                    if ( j < c && i > 1 && g[i-1][j+1] == '*' ) continue;
                    num++;
//                    printf("%d %d\n", i, j);
                }
            }
//        for ( int i = 1; i <= r; ++i, printf("\n") ) for ( int j = 1; j <= c; ++j ) printf("%c", g[i][j]); 
        printf("%d\n", num);
    }
}


你可能感兴趣的:(UVa 11244 counting stars ( 搜索 BFS))