改好了,修改过的地方做了标注。
```cpp
#include<bits/stdc++.h>
using namespace std;
int dx[8] = {1, 1, 1, 0, 0, -1,-1,-1 };
int dy[8] = {1, 0,-1, 1,-1, 0, 1,-1 };
int n=100; //modified
vector<vector<char>>a(n+10,vector<char>(n+10,-1));
vector<vector<int>>b(0,vector<int>(2));//modified
vector<vector<char>>protect(n+10,vector<char>(n+10,'*'));
string k="yizhong";
void find(int q) {
int x=b[q][0];
int y=b[q][1];
for(int j=0; j<8; j++) {
for(int i=0; i<=6; i++) { //modified
if(a[x+i*dx[j]][y+i*dy[j]]!=k[i])break; //modified
if(i==6)for(int t=0; t<=6; t++)protect[x+t*dx[j]][y+t*dy[j]]=k[t]; //modified
}
}
}
int main()
{
cin>>n;
int lenb=0;
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
cin>>a[i][j];
//cout<<a[i][j]<<" ";
//if(j==n)cout<<endl;
if(a[i][j]=='y') {
b.push_back(vector<int> {i,j});
lenb++;
}
}
}
for(int i=0; i<lenb; i++) {
find(i);
}
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
cout<<protect[i][j];
if(j==n)cout<<endl;
}
}
return 0;
}
```
by Gold14526 @ 2024-02-16 22:29:28
@[Gold14526](/user/345930) 谢谢大佬!过了,但是我想问您一下就是如果设全局数组的话,里边就不能带有main函数里cin的变量n吗,必须要提前把n赋值吗。想要实现全局数组大小为mian函数里输入的变量应该怎么办,要不然函数写着太麻烦吧。
by Shrimp123 @ 2024-02-17 14:46:57
@[Shrimp123](/user/1275384) 貌似不行
by Gold14526 @ 2024-02-17 22:35:24
@[Gold14526](/user/345930) 好的感谢
by Shrimp123 @ 2024-02-17 23:18:22