程序:
#include <bits/stdc++.h>
using namespace std;
const int N=3e2;
int a,b,k;
int _a[N][N],number[N][N],_b[N][N];
int get(int pos1X,int pos1Y)
{
int x=pos1X-k,y=pos1Y-k;
swap(x,pos1X);
swap(y,pos1Y);
int answer=number[x][y]-number[pos1X][y]-number[x][pos1Y]+number[pos1X][pos1Y];
return answer;
}
int main()
{
int answer=0,x,y;
cin>>a>>b>>k;
k--;k--;
for (int i=1;i<=a;i++)
{
string temp="";
cin>>temp;
for (int j=0;j<b;j++)
{
if (temp[j]=='*') _a[i][j+1]=1;
}
}
for (int i=1;i<=a;i++)
{
for (int j=1;j<=b;j++)
{
number[i][j]=number[i-1][j]+number[i][j-1]-number[i-1][j-1]+_a[i][j];
}
}
for (int i=2;i<=a-1;i++)
{
for (int j=2;j<=b-1;j++)
{
if (answer!=max(answer,get(i,j)))
{
answer=max(answer,get(i,j));x=i;y=j;
}
}
}cout<<answer<<endl;
for (int i=1;i<=a;i++)
{
for (int j=1;j<=b;j++)
{
if (i==x+1 && j==y+1 || i==x-k && j==y-k || i==x+1 && j==y-k || i==x-k && j==y+1){cout<<"+";continue;}
if (j<=y && j>=y-k+1 && i==x-k || i==x+1 && j<=y && j>=y-k+1){cout<<"-";continue;}
if (i<=x && i>=x-k+1 && j==y-k || j==y+1 && i<=x && i>=x-k+1){cout<<"|";continue;}
if (_a[i][j]==0) cout<<".";
if (_a[i][j]==1) cout<<"*";
}
cout<<endl;
}
return 0;
}
不知道哪里出了问题 dalao速助 orz