zoukankan      html  css  js  c++  java
  • poj2612

    简单模拟

    View Code
    #include <iostream>
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    using namespace std;

    #define maxn 11

    int n;
    bool map[maxn][maxn], touched;
    char out[maxn][maxn];

    void input()
    {
    for (int i = 0; i < n; i++)
    {
    for (int j = 0; j < n; j++)
    {
    char ch = getchar();
    if (ch == '.')
    map[i][j]
    = false;
    else
    map[i][j]
    = true;
    }
    getchar();
    }
    }

    int boom(int x, int y)
    {
    if (x < 0 || y < 0 || x >= n || y >= n)
    return 0;
    if (map[x][y])
    return 1;
    return 0;
    }

    int cal(int x, int y)
    {
    return boom(x + 1, y) + boom(x + 1, y + 1) + boom(x + 1, y - 1) + boom(x - 1, y) + boom(x - 1, y + 1) + boom(x - 1, y - 1) + boom(x, y + 1) + boom(x, y - 1);
    }

    void work()
    {
    touched
    = false;
    for (int i = 0; i < n; i++)
    {
    for (int j = 0; j < n; j++)
    {
    char ch = getchar();
    if (ch == '.')
    out[i][j] = '.';
    else
    {
    out[i][j] = cal(i, j) + '0';
    if (map[i][j])
    touched
    = true;
    }
    }
    getchar();
    }
    }

    void output()
    {
    for (int i = 0; i < n; i++)
    {
    for (int j = 0; j < n; j++)
    {
    if (touched && map[i][j])
    {
    printf(
    "*");
    continue;
    }
    printf(
    "%c", out[i][j]);
    }
    printf(
    "\n");
    }
    }

    int main()
    {
    //freopen("t.txt", "r", stdin);
    scanf("%d", &n);
    getchar();
    input();
    work();
    output();
    return 0;
    }

  • 相关阅读:
    深度学习和神经网络的区别是什么
    各种数据类型范围
    排队接水
    最大整数
    马拉松接力赛
    合并果子
    统计学生信息(使用链表完成)
    删除数组中的元素(链表)
    求最大公约数(最小公倍数)
    十进制转化成八进制(一到十六进制)
  • 原文地址:https://www.cnblogs.com/rainydays/p/2047582.html
Copyright © 2011-2022 走看看