cynic


私信TA

用户名:202210711108

访问量:2079

签 名:

等  级
排  名 4868
经  验 1556
参赛次数 0
文章发表 10
年  龄 0
在职情况 学生
学  校
专  业 计算机

  自我简介:

TA的其他文章

解题思路:
    检测每一个字符周围八个字符是否存在地雷,考虑到字符四个角落及四条边存在限制,因此在四个角落及四条边外面在套上另外一层空字符串,使得每一个输入的字符串都存在八个领字符串。
注意事项:

参考代码:

#include <iostream>

#include <cstring>

using namespace std;

int main() 

{

    int a, b;

    int num = 1;

    while (cin >> a >> b)

    {

        if (a == 0 && b == 0)

            break;

        string* s = new string[a];

        for (int i = 0; i < a; i++)

        {

            cin >> s[i];

        }

        cout << "Field #" << num << ":" << endl;

        string* str = new string[a + 2];

        string s1 = "";

        for (int i = 0; i < b+2; i++)

        {

            s1 += '0';

        }

        string s2 = s1;

        str[0] = s1;

        str[a + 1] = s2;

        for (int i = 0; i < a; i++)

        {

            str[i + 1] ='0'+ s[i]+'0';

        }

        for (int y = 1; y < a + 1; y++)

        {

            for (int x = 1; x < b + 1; x++)

            {

                if (str[y][x] == '*')

                {

                    cout << '*';

                    continue;

                }

                else

                {

                    int c = 0;

                    if (str[y - 1][x - 1] == '*')

                        c++;

                    if (str[y - 1][x] == '*')

                        c++;

                    if (str[y - 1][x + 1] == '*')

                        c++;

                    if (str[y][x - 1] == '*')

                        c++;

                    if (str[y][x + 1] == '*')

                        c++;

                    if (str[y + 1][x - 1] == '*')

                        c++;

                    if (str[y + 1][x] == '*')

                        c++;

                    if (str[y + 1][x + 1] == '*')

                        c++;

                    cout << c;

                }

            }

            cout << endl;

        }

        num++;

        cout << endl;

    }

    return 0;

}


 

0.0分

1 人评分

  评论区