p没初始化
by Peter258035613 @ 2024-08-06 18:34:09
格式错误 @[hsy_123](/user/1415827)
by lij123 @ 2024-08-06 18:39:37
改了3处
```cpp
#include <bits/stdc++.h>//第一处
using namespace std;
int n,pos[4][2]={0,1, 1,0, 0,-1, -1,0};
int x=1,y=1,d=0,p[15][15];
int main(){
memset(p,0,sizeof(p));//第二处
cin>>n;
for(int i=1;i<=n*n;i++){
p[x][y]=i;
int tx=x+pos[d][0];
int ty=y+pos[d][1];
if(1<=tx&&tx<=n&&1<=ty&&ty<=n&&p[tx][ty]==0){
x=tx;
y=ty;
}else{
d=(d+1)%4;
x=x+pos[d][0];
y=y+pos[d][1];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)
cout<<setw(3)<<p[i][j];//第三处
cout<<endl;
}
return 0;
}
```
@[hsy_123](/user/1415827)
by Jokersheng @ 2024-08-06 23:50:15
@[shengshengzqs](/user/1243618) 谢谢大佬 AC了
by hsy_123 @ 2024-08-07 13:44:27
@[hsy_123](/user/1415827) 实际上你只有第三处有问题
by dthythxth_Huge_Brain @ 2024-08-10 22:10:25