| Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 77940 | 牛延希 | 蛇形矩阵 | C++ | Wrong Answer | 0 MS | 280 KB | 612 | 2024-06-15 17:39:21 |
#include<iostream> #include<iomanip> using namespace std; int main(){ int n,p,q,a[101][101]; cin>>n; int x=-1,y=n-1,s=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ a[i][j]=0; } }for(int i=1;i<=n/2+1;i++){ while(a[x+1][y]==0 && x+1<=n-1){ a[++x][y]=++s; }while(a[x][y-1]==0 && y-1>=0){ a[x][--y]=++s; }while(a[x-1][y]==0 && x-1>=0){ a[--x][y]=++s; }while(a[x][y+1]==0 && y+1<=n-1){ a[x][++y]=++s; } }for(int i=0;i<n;i++){ for(int j=n-1;j>=0;j--){ cout<<setw(3)<<a[i][j]; }cout<<endl; } return 0; }
------Input------
4
------Answer-----
1 8 9 16 2 7 10 15 3 6 11 14 4 5 12 13
------Your output-----
1 12 11 10 2 13 16 9 3 14 15 8 4 5 6 7