Why didn't it output
2024-08-14 20:52:42
发布于:浙江
42阅读
0回复
0点赞
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int n,m,dsbx[8] = {1,1,1,0,0,-1,-1,-1},dsby[8] = {1,0,-1,1,-1,-1,0,1};
    char ch[101][101];
    for(int i = 1; i <= n; i++)for(int j = 1; j <= n; j++) cin >> ch[i][j];
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if(ch[i][j] == '*') cout << "*";
            else if(ch[i][j] == '?')
            {
                int cnt = 0;
                for(int _ = 0; _ < 8; _++)
                {
                    int x = dsbx[_] + i,y = j + dsby[_];
                    if(x >= 1 && x <= n && y >= 1 && y <= m)
                    {
                        cnt++;
                    }
                }
                cout << cnt;
            }
            else continue;
        }
        cout << endl;
    }
}
全部评论 1
你忘记输入n,m了
2025-01-02 来自 广东
0








有帮助,赞一个