import copy
m,n,k=map(int,input().split())
ans=[[]]*m
ans1=[]
ans2=[]
out=[]
a=m-1
b=0
count=0
for i in range(m):
ans1=[]
x=input()
for j in x:
ans1.append(j)
ans[i]=ans1[:]
num=list(map(int,input().split()))
ans2=copy.deepcopy(ans)
for i in num:
if i==0 and a-1>=0:
a-=1
elif i==1 and b+1<n-1:
b+=1
elif i==2 and a+1<=m-1 and b+1<n-1:
a+=1
b+=1
elif i==4 and b-1>=0:
b-=1
elif i==3 and a+1<m-1:
a+=1
elif i==5 and a-1>=0 and b-1>=0:
a-=1
b-=1
print(ans[a][b],end="")
if ans2[a][b]!=0:
ans2[a][b]=0
count+=1
print()
print(count)
請教以上哪裡出錯
import copy
m,n,k=map(int,input().split())
ans=[[]]*m
ans1=[]
ans2=[]
out=[]
a=m-1
b=0
count=0
for i in range(m):
ans1=[]
x=input()
for j in x:
ans1.append(j)
ans[i]=ans1[:]
num=list(map(int,input().split()))
ans2=copy.deepcopy(ans)
for i in num:
if i==0 and a-1>=0:
a-=1
elif i==1 and b+1 b+=1
elif i==2 and a+1<=m-1 and b+1 a+=1
b+=1
elif i==4 and b-1>=0:
b-=1
elif i==3 and a+1 a+=1
elif i==5 and a-1>=0 and b-1>=0:
a-=1
b-=1
print(ans[a][b],end="")
if ans2[a][b]!=0:
ans2[a][b]=0
count+=1
print()
print(count)
請教以上哪裡出錯
兩大問題
1:所有邊界都是<=(m-1)or (n-1) >=0(ex:a+1<=m-1)
2.在進行計算不同字數時,不同row 和column可能有相同的字母,依據你的程式會當成不同的,建議使用set會比較好做。
加油!!