###### tags: `APCS` `c++` `題解` `ZeroJudge` `陣列` # 題解 zerojudge c292: APCS2017-0304-3數字龍捲風 ## 陣列 ```cpp= #include<bits/stdc++.h> using namespace std; int main(){ int n,h; cin>>n>>h; int l[50][50]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>l[j][i]; } } int index=0; cout<<l[(n-1)/2][(n-1)/2]; int dx[4][4]={{-1,0,1,0},{0,1,0,-1},{1,0,-1,0},{0,-1,0,1}}; int dy[4][4]={{0,-1,0,1},{-1,0,1,0},{0,1,0,-1},{1,0,-1,0}}; int x=(n-1)/2,y=(n-1)/2; int count=n*n-1-n; int c=1; while(count>=0){ for(int i=0;i<2;i++){ for(int j=0;j<c;j++){ x+=dx[h][index]; y+=dy[h][index]; cout<<l[x][y]; count--; } index=(index+1)%4; } c++; } c--; for(int j=0;j<c;j++){ x+=dx[h][index]; y+=dy[h][index]; cout<<l[x][y]; } cout<<'\n'; } ```