• 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("
    ");
        }
    
    }
    
  • 相关阅读:
    开源博客平台WordPress十岁啦!
    (转载)C# Attribute 用法备忘
    hibernate入门
    Hibernate对象关系映射基础
    struts2UI标签
    struts2文件上传2(多文件)
    struts2验证(手工)
    通过修改注册表改变txt文件的默认打开方式
    struts2验证(XML)
    Struts国际化
  • 原文地址:https://www.cnblogs.com/amonqsq/p/13585082.html
Copyright © 2020-2023  润新知