Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
2831 | 邓小龙 | 方阵填数 | C++ | Accepted | 0 MS | 296 KB | 719 | 2024-03-02 18:13:41 |
# include<iostream> using namespace std; int main(){ int n; cin>>n; int juzhen[101][101]={}, a = -1, b = n-1, way = 2, out = 1; while(out <= n*n){ if(way == 1){ if(juzhen[a][b+1]!=0||b>n-2){ way++; continue; } b++; } else if(way == 2){ if(juzhen[a+1][b]!=0||a>n-2){ way++; continue; } a++; } else if(way == 3){ if(juzhen[a][b-1]!=0||b<1){ way++; continue; } b--; } else if(way == 4){ if(juzhen[a-1][b]!=0||a<1){ way = 1; continue; } a--; } juzhen[a][b] = out; out++; } for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++)cout<<juzhen[i][j]<<" "; cout<<endl; } return 0; }