1 solutions

  • 0
    @ 2026-9-28 21:31:23
    #include<bits/stdc++.h>
    using namespace std;
    char a[510][510];
    int dx[]={-1,-1,-1,0,0,1,1,1};
    int dy[]={-1,0,1,-1,1,-1,0,1};
    int main()
    {
    	int n,m,p;
    	cin>>n>>m>>p;
    	
    	while(p>0)
    	{
    		int x,y;
    		cin>>x>>y;
    		a[x][y]='*';
    		p--;
    	}
    	int c=0;
    	for(int i=1;i<=n;i++)
    	{
    		for(int j=1;j<=m;j++)
    		{
    			if(a[i][j]!='*')
    			{
    				for(int k=0;k<8;k++)
    				{
    					int ii=i+dx[k],jj=j+dy[k];
    				//	cout<<ii<<' '<<jj<<' ';
    					if(a[ii][jj]=='*')
    					{
    						c++;
    					}
    				}
    				cout<<c<<' ';
    				c=0;
    			}
    			else
    			{
    				cout<<'*'<<' ';
    				continue;
    			}
    		}
    		cout<<endl;
    	}
    	return 0;
    }
    

    Information

    ID
    3540
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    3
    Tags
    # Submissions
    9
    Accepted
    4
    Uploaded By