编辑代码

#include <stdio.h>
int main ()
{
    int m,n;
    int matrix[100][100];
    int scatter_x=0,scatter_y=0,max_count=0,count=0;

    scanf("%d %d",&m,&n);

    //按行输入,并且判断稀疏行
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++)
        {
            scanf("%d",&matrix[i][j]);
            if(matrix[i][j]==0 && j!=(n-1))
            {
                count++;
            }
            else
            {
                if(matrix[i][j]==0 && j==(n-1))
                {
                    count++;
                }

                if(count>max_count)//取最大的连续0总数
                {
                    max_count=count;
                }
                count=0;
            }
        }
        if(max_count>=n/2)
        {
            scatter_x++;
        }
        max_count=0;
    }

    //判断稀疏列
    for(int j=0;j<n;j++)
    {
        for(int i=0;i<m;i++)
        {
            if(matrix[i][j]==0 && i!=(m-1))
            {
                count++;
            }
            else
            {
                if(matrix[i][j]==0 && i==(m-1))
                {
                    count++;
                }

                if(count>max_count)//取最大的连续0总数
                {
                    max_count=count;
                }
                count=0;
            }
        }
        if(max_count>=m/2)
        {
            scatter_y++;
        }
        max_count=0;
    }

    printf("%d %d\n",scatter_x,scatter_y);
}