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

  • 相关阅读:
    数组——基础
    程序流程控制——循环结构
    程序流程控制——分支结构
    运算符
    进制
    变 量
    Java中的名称命名规范
    标识符(Identifier)
    保留字(reserved word)
    关键字
  • 原文地址:https://www.cnblogs.com/rainydays/p/2047582.html
Copyright © 2011-2022 走看看