#16630: AC解


henrytsui000 (霸氣@浩堂 今年17歲 文教被死當)

學校 : 國立交通大學
編號 : 86611
來源 : [42.72.10.231]
最後登入時間 :
2022-08-14 18:08:59
c292. APCS2017-0304-3數字龍捲風 -- 2017年3月APCS | From: [140.113.136.219] | 發表日期 : 2019-01-23 10:51

#include<iostream>
using namespace std;
int main(){
int area;
while(cin>>area){
int arr[area][area],st,key[2],move=1,cnt,t;
cnt=t=0;
cin>>st;
for(int i=0;i<area;i++)
for(int j=0;j<area;j++)
cin>>arr[i][j];
key[0]=key[1]=area/2;
while(true){
for(int i=0;i<move;i++){
cout<<arr[key[0]][key[1]];
if(st==0)key[1]--;
else if(st==1)key[0]--;
else if(st==2)key[1]++;
else key[0]++;
cnt++;
}
if(st<3)st++;
else st=0;
t++;
if(t%2==0)move++;
if(cnt==area*area)break;
}
}

/*

請刪掉這一段

雖然註解掉了

t是紀錄是否該增加移動數量,因為每換兩次方向都要多走一步

key紀錄目前位置

area存陣列大小

arr就是放數字的陣列

cnt是計算是否走訪完所有元素(應經過area*area個元素)

st紀錄方向 0>1>2>3>0 周而復始

*/


return 0;
}

 
ZeroJudge Forum