3 solutions

  • 0
    @ 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
      @ 2024-10-7 15:35:51

      c++'''#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(i1||in||j1||jm) { 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; } '''

      • -1
        @ 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;
        }
        
        
      • 1

      Information

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