3 solutions

  • 1
    @ 2025-12-6 15:57:22
    #include<bits/stdc++.h>
    using namespace std;
    int a[110][110],b[110][110];
    int main(){
    	int n,m;
    	cin>>n>>m;
    	for(int i=1;i<=n;i++){
    		for(int j=1;j<=m;j++){
    			cin>>a[i][j];
    		}
    	}
    	for(int i=1;i<=n;i++){
    		for(int j=1;j<=m;j++){
    //把除了周围四条边以外的数为该数及其上下左右相邻四个像数的平均(舍入到最接近的整数)
    			if(i==n||i==1||j==m||j==1){ 
    				cout<<a[i][j]<<" ";
    			}else{
    				b[i][j]=round((a[i][j]+a[i-1][j]+a[i+1][j]+a[i][j-1]+a[i][j+1])/5.0);
    				cout<<b[i][j]<<' ';
    			}
    		}
    		cout<<'\n';
    	}
    	return 0;
    }
    
    • -2
      @ 2024-4-3 19:15:56
      #include<bits/stdc++.h>
      using namespace std;
      const int N=110,M=110;
      int a[N][M];
      int b[N][M];
      int main()
      {
      	int n,m;
      	cin>>n>>m;
      	for(int i=1;i<=n;i++)
      	{
      		for(int j=1;j<=m;j++)
      		{
      			cin>>a[i][j];
      		}
      	}
      	for(int i=1;i<=n;i++)
      	{
      		for(int j=1;j<=m;j++)
      		{
      			if(i==1||i==n||j==1||j==m)
      			{
      				b[i][j]=a[i][j]; 
      			}
      			else
      			{
      				double h=(a[i][j]+a[i-1][j]+a[i+1][j]+a[i][j-1]+a[i][j+1])/5.0;
      				int r=round(h);
      				b[i][j]=r;
      			}
      		}
      	}
      	for(int i=1;i<=n;i++)
      	{
      		cout<<endl;
      		for(int j=1;j<=m;j++)
      		{
      			cout<<b[i][j]<<" ";
      		}
      	}
          return 0;
      }
      
      
      • -3
        @ 2025-3-15 11:14:04
        #include<bits/stdc++.h>
        using namespace std;
        const int N=110,M=110;
        int a[N][M];
        int b[N][M];
        int main()
        {
        	int n,m;
        	cin>>n>>m;
        	for(int i=1;i<=n;i++)
        	{
        		for(int j=1;j<=m;j++)
        		{
        			cin>>a[i][j];
        		}
        	}
        	for(int i=1;i<=n;i++)
        	{
        		for(int j=1;j<=m;j++)
        		{
        			if(i==1
        • 1

        Information

        ID
        906
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        1
        Tags
        (None)
        # Submissions
        123
        Accepted
        42
        Uploaded By