竞赛讨论区 > 这道题这么写哪里错了
头像
CR7MADRID
发布于 2020-04-26 20:41
+ 关注

这道题这么写哪里错了

import java.util.Scanner;

public class LakeCounting {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        int p=0;
        int N = in.nextInt();
        int M = in.nextInt();
        boolean b[][] = new boolean[N][M];
        for(int i = 0;i< N;i++)
        {
            for(int j =0;j<M;j++)
            {
                byte s = in.nextByte();    
                char c= (char)s;
                if(c=='W')
                    b[i][j]=true;
                else
                    b[i][j]=false;
            }
        }
        for(int i =1;i<N-1;i++)
        {
            for(int j=1;j<M-1;j++)
            {
                if(b[i][j]==true&&b[i-1][j]==true&&b[i+1][j]==true&&b[i][j-1]==true&&b[i][j+1]==true)
                p++;    
            }
        }
        System.out.print(p);
        in.close();
    }

}

全部评论

(0) 回帖
加载中...
话题 回帖

本文相关内容

等你来战

查看全部

热门推荐