• 模拟与高精度 P2670 扫雷游戏


    题目

    https://www.luogu.com.cn/problem/P2670

    代码

    #include<iostream>
    #include<cstdio>
    #include<string>
    #include<cstring>
    using namespace std;
    int answer[200][200];
    #define inf 500
    int main()
    {
        int n, m;
        string tmp;
        scanf("%d%d", &n, &m);
        for (int i = 0; i < n; i++)
        {
            cin >> tmp;
            for (int j = 0; j < m; j++)
            {
                if (tmp[j] == '*')
                {
                    if (i - 1 >= 0 && j - 1 >= 0)answer[i - 1][j - 1]++;
                    if (i - 1 >= 0)answer[i - 1][j]++;
                    if ( j - 1 >= 0)answer[i][j - 1]++;
                    answer[i][j] = -inf;
                    if (i +1 <n && j -1>=0)answer[i + 1][j-1]++;
                    if (i + 1 <n )answer[i + 1][j]++;
                    if (i - 1 >= 0 && j + 1<m)answer[i - 1][j + 1]++;
                    if ( j + 1 <m)answer[i][j + 1]++;
                    if (i + 1 <n && j +1<m)answer[i + 1][j + 1]++;
                }
            }
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (answer[i][j] < 0)
                    printf("*");
                else
                    printf("%d", answer[i][j]);
            }
            printf("
    ");
        }
    
    
    }
  • 相关阅读:
    input 蓝边
    4.【ac自动机】模式串匹配
    3.【二叉树】最近公共祖先
    2.【动态规划】最长回文子串
    1. 【线段树】
    DbUtil
    oauth2
    cas
    Spring-security-web
    JSON Web Tokens
  • 原文地址:https://www.cnblogs.com/Jason66661010/p/12834512.html
Copyright © 2020-2023  润新知