按照慣例,APCS的第二題就是考二維陣列的運用,特別是邊界的判別。解這題的時候如果你可以畫個圖,或是心中畫個圖的畫就會簡單許多。
現實的資料
m,n,k = [int(i) for i in input().split()]
s = []
for i in range(m):
s.append(input())
step = [int(i) for i in input().split()]
table = [[-1,0],[0,1],[1,1],[1,0],[0,-1],[-1,-1]]
x,y = 0,m-1
sets = set()
ans = ''
for i in step:
yy,xx = table[i]
if xx+x < 0 or xx+x >= n or yy+y < 0 or yy+y >= m:
ans += s[y][x]
sets.add(s[y][x])
continue
y,x = yy+y,xx+x
ans += s[y][x]
sets.add(s[y][x])
print(ans)
print(len(sets))
有問題歡迎留言,或email與我討論。
沒有留言:
張貼留言