• 201512-2 消除类游戏


    实现

    #include <cstdio>
    
    #define MAXN 32
    
    int chess[MAXN][MAXN];
    int marks[MAXN][MAXN];
    
    int main() {
        int row, col;
    
        scanf("%d%d",&row,&col);
    
        for (int i = 0;i < row;++i) {
            for (int j = 0;j < col;++j) {
                scanf("%d",&chess[i][j]);
            }
        }
        
        for (int i = 0;i < row;++i) {
            int pre_val = 0;
            int same_cnt = 0;
            for (int j = 0;j < col;++j) {
                if (pre_val == chess[i][j]) {
                    same_cnt+=1;
                    if (j == col - 1 && same_cnt >= 2) {
                        for (;same_cnt >= 0; --same_cnt) {
                            marks[i][j - same_cnt] = 1;
                        }
                    }
                } else if (pre_val != chess[i][j]){
                    if(same_cnt >= 2) {
                        for (;same_cnt >= 0; --same_cnt) {
                            marks[i][j - same_cnt - 1] = 1;
                        }
                    }
                    same_cnt = 0;
                } 
                pre_val = chess[i][j];
            }
        }
    
        for (int j = 0;j < col;++j) {
            int pre_val = 0;
            int same_cnt = 0;
            for (int i = 0;i < row;++i) {
                if (pre_val == chess[i][j]) {
                    same_cnt+=1;
                    if ( i == row - 1 && same_cnt >= 2) {
                        for (;same_cnt >= 0; --same_cnt) {
                            marks[i - same_cnt][j] = 1;
                        }
                    }
                }  else if (pre_val != chess[i][j]) {
                    if (same_cnt >= 2) {
                        for (;same_cnt >= 0;--same_cnt) {
                            marks[i - same_cnt - 1][j] = 1;
                        }
                    }
                    same_cnt = 0;
                }
                pre_val = chess[i][j];
            }
        }
    
        for (int i = 0;i < row;++i) {
            for (int j = 0;j < col;++j) {
                if (marks[i][j] == 1) {
                    printf("0 ");
                } else {
                    printf("%d ",chess[i][j]);
                }
            }
            printf("
    ");
        }
    
    }
    
  • 相关阅读:
    Day20:Decorator and Metaclass
    Day19:hasattribute;getattribute;seattributet;delattribute
    Day18:polymorphic and reflection
    Day17:call the base class
    ACL权限
    内置函数
    用户配置文件-影子文件
    用户配置文件-用户信息文件
    脚本安装包
    定义函数
  • 原文地址:https://www.cnblogs.com/amonqsq/p/13585082.html
Copyright © 2020-2023  润新知