指针原来是套娃的


私信TA

用户名:uq_92467646842

访问量:43406

签 名:

数学改变科学,科学改变世界

等  级
排  名 10
经  验 25179
参赛次数 49
文章发表 128
年  龄 0
在职情况 学生
学  校
专  业 物联网工程

  自我简介:

QQ:2830671713

对找到的草进行扩展


参考代码:

#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;

int main()
{
	char a[101][101];
int now=1;
int m_tot=0;
int z_tot=0;
int ans=0;
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>a[i][j];
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(a[i][j]=='#')
            {
                if(a[i+1][j]=='#')
                {
                    a[i][j]='.';
                    a[i+1][j]='.';
                    ans++;
                }
                else if(a[i-1][j]=='#')
                {
                    a[i][j]='.';
                    a[i+1][j]='.';
                    ans++;
                }
                else if(a[i][j+1]=='#')
                {
                    a[i][j]='.';
                    a[i][j+1]='.';
                    ans++;
                }
                else if(a[i][j-1]=='#')
                {
                    a[i][j]='.';
                    a[i+1][j]='.';
                    ans++;
                }
                else
                {
                    a[i][j]='.';
                    ans++;
                }
            }
        }
    }
    cout<<ans;
    return 0;
}


 

0.0分

154 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区