超长的代码,,,希望大佬能读完
查看原帖
超长的代码,,,希望大佬能读完
1131905
yoyoSGH楼主2023/12/16 10:42

10分蒟蒻

#include<bits/stdc++.h>
using namespace std;
int main() {
	double x;
	int m,n,a[105][105],b[105][105];
	cin>>m>>n;
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cin>>a[i][j];
			if(i==1||i==m||j==1||j==n) b[i][j]=a[i][j];
		}
	}
	for(int i=2;i<m;i++)
	{
		for(int j=2;j<n;j++)
		{
			x=(double)((a[i-1][j]+a[i+1][j]+a[i][j-1]+a[i][j+1]+a[i][j])/5);			
			if(x<(floor(x)+0.5)) b[i][j]=floor(x);
			else b[i][j]=ceil(x);
		}
	}
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cout<<b[i][j]<<" ";
		}
		cout<<endl;
	}
	return 0;
}

或许只过了样例,,,

2023/12/16 10:42
加载中...