#include<stdio.h> #include<stdlib.h> int x[21][21]; int main() { int i,j,n,m; // freopen("input.txt","r",stdin); while(scanf("%d%d",&n,&m)!=EOF) { int s[21][21]= {0}; if(m==0||n==0) break; for(i=0; i<n; i++) for(j=0; j<m; j++) scanf("%d",&x[i][j]); for(i=0; i<n; i++) for(j=0; j<m; j++) { if(i>0&&i<n-1) { if(x[i-1][j]*x[i][j]<0) //up s[i][j]+=abs(x[i-1][j]); else s[i][j]-=abs(x[i-1][j]); if(x[i+1][j]*x[i][j]<0) // down s[i][j]+=abs(x[i+1][j]); else s[i][j]-=abs(x[i+1][j]); } if(j>0&&j<m-1) { if(x[i][j-1]*x[i][j]<0) //left s[i][j]+=abs(x[i][j-1]); else s[i][j]-=abs(x[i][j-1]); if(x[i][j+1]*x[i][j]<0) //rigth s[i][j]+=abs(x[i][j+1]); else s[i][j]-=abs(x[i][j+1]); } if(n>1) { if(i==0) { if(x[i+1][j]*x[i][j]<0) // down s[i][j]+=abs(x[i+1][j]); else s[i][j]-=abs(x[i+1][j]); } if(i==n-1) { if(x[i-1][j]*x[i][j]<0) //up s[i][j]+=abs(x[i-1][j]); else s[i][j]-=abs(x[i-1][j]); } } if(m>1) { if(j==0) { if(x[i][j+1]*x[i][j]<0) //rigth s[i][j]+=abs(x[i][j+1]); else s[i][j]-=abs(x[i][j+1]); } if(j==m-1) { if(x[i][j-1]*x[i][j]<0) //left s[i][j]+=abs(x[i][j-1]); else s[i][j]-=abs(x[i][j-1]); } } if(m==1&&n==1) { s[0][0]=0; } } int max=s[0][0],q=0,p=0; for(i=0; i<n; i++) for(j=0; j<m; j++) { if(s[i][j]>max) { max=s[i][j]; p=i; q=j; } } printf("%d %d %d\n",p+1,q+1,max); } return 0; }
时间: 2024-10-01 17:45:04