美文网首页
CCF201512-2 消除类游戏(JAVA版)

CCF201512-2 消除类游戏(JAVA版)

作者: 巨鹿lx | 来源:发表于2020-03-21 09:39 被阅读0次
import java.util.Arrays;
import java.util.Scanner;

public class Main{
    static int N = 35;
    static int a[][] = new int[N][N];
    static boolean st[][] = new boolean[N][N];
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        for(int i  = 1; i <= n ; i++) {
            for(int j = 1; j <= m ;j ++) {
                a[i][j] = scanner.nextInt();
            }
        }
        for(int  i = 1; i <= n; i ++) {
            for(int j = 1; j <= m ; j ++) {
                if(j+1<=m&&j-1>0) {//横的不越界检查横的
                    if(a[i][j]==a[i][j-1]&&a[i][j]==a[i][j+1]) {
                        st[i][j] = true;st[i][j+1] = true;st[i][j-1] = true;
                    }
                }
                if(i-1>0&&i+1<=n) {//竖的不越界检查竖的
                    if(a[i][j]==a[i-1][j]&&a[i][j]==a[i+1][j]) {
                        st[i][j] = true;st[i+1][j] = true;st[i-1][j] = true;
                    }
                }
            }
        }
        for(int i = 1 ;i <= n; i ++) {
            for(int j = 1; j <= m ; j ++) {
                System.out.print((st[i][j]?0:a[i][j])+" ");
            }
            System.out.println();
        }
    }
}

相关文章

网友评论

      本文标题:CCF201512-2 消除类游戏(JAVA版)

      本文链接:https://www.haomeiwen.com/subject/zuzeyhtx.html