코드업6098 성실한개미

주리·2022년 12월 27일
0

문제

입력예시

1 1 1 1 1 1 1 1 1 1
1 0 0 1 0 0 0 0 0 1
1 0 0 1 1 1 0 0 0 1
1 0 0 0 0 0 0 1 0 1
1 0 0 0 0 0 0 1 0 1
1 0 0 0 0 1 0 1 0 1
1 0 0 0 0 1 2 1 0 1
1 0 0 0 0 1 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1

출력예시

1 1 1 1 1 1 1 1 1 1
1 9 9 1 0 0 0 0 0 1
1 0 9 1 1 1 0 0 0 1
1 0 9 9 9 9 9 1 0 1
1 0 0 0 0 0 9 1 0 1
1 0 0 0 0 1 9 1 0 1
1 0 0 0 0 1 9 1 0 1
1 0 0 0 0 1 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1

코드

graph=[]
for i in range(10):
	a = list(map(int,input().split()))
	graph.append(a)

x=1
y=1

while(True):
	
	if graph[x][y+1]==2 :
		#print('x0',x,'y',y)
		graph[x][y]=9
		graph[x][y+1]=9
		break
	elif graph[x][y+1]==1 and graph[x+1][y]==2:
		graph[x][y]=9
		graph[x+1][y]=9
		break
	elif graph[x][y+1]==1 and graph[x+1][y]==0:
		#print('x2',x,'y',y)
		graph[x][y]=9
		x +=1
	elif graph[x][y+1]==0:
		#print('x1',x,'y',y)
		graph[x][y]=9
		y += 1
	else:
		#print('x3',x,'y',y)
		graph[x][y]=9
		break

for i in range(10):
	for j in range(10):
		print(graph[i][j], end=' ')
	print()

주의

  • if문의 향연,,,
  • while(True)를 사용할 때는 break를 잘 걸어주어야 한다
    안그러면 시간초과 어쩌고가 나더라고?
profile
완벽한 글 보다, 그 과정들을 기록하는 개발자

0개의 댓글