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;
    }

  • 相关阅读:
    HAL 分析
    Ubuntu 11.04 安装后要做的20件事情
    IOStableViewCell自适应高度cell里面放的是UIlable
    IOS支持的字体
    IOS TableView学习资源
    产品与市场
    软件质量与公司盈利
    计算机流派
    让你的软件支持繁体中文
    系统规划设置心得
  • 原文地址:https://www.cnblogs.com/rainydays/p/2047582.html
Copyright © 2011-2022 走看看