Skip to content

Commit c503644

Browse files
authored
[BOJ] 20125 쿠키의 신체 측정 (S4)
1 parent 97da1ec commit c503644

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

김지호/11주차/260309.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# https://www.acmicpc.net/problem/20125
2+
# 쿠키의 신체 측정, 실버4
3+
4+
import sys
5+
sys.stdin = open("../../../input.txt",'r')
6+
7+
N = int(input()) # 판의 크기
8+
9+
board = []
10+
board.append([-1] * (N+1))
11+
12+
def print_2d_arr(array):
13+
for arr in array:
14+
print(arr)
15+
16+
17+
for _ in range(N):
18+
array = list(input())
19+
array.insert(0,-1)
20+
21+
board.append(array)
22+
23+
# print_2d_arr(board)
24+
25+
hasFoundFirst = False
26+
heart = None # 심장 위치
27+
for row in range(1,N+1):
28+
for col in range(1,N+1):
29+
value = board[row][col]
30+
31+
if value == "*":
32+
# print(f"* 찾음 : {row},{col}")
33+
# 처음 찾는 경우
34+
if not hasFoundFirst:
35+
heart = [row+1,col]
36+
hasFoundFirst = True
37+
break
38+
if hasFoundFirst:
39+
break
40+
41+
answer = []
42+
# 왼쪽 팔
43+
heart_row, heart_col = heart
44+
# print(f"심장 위치 : [{heart_row},{heart_col}]")
45+
count = 0
46+
for col in range(heart_col-1, 0, -1):
47+
if board[heart_row][col] == "*":
48+
count += 1
49+
else:
50+
break
51+
answer.append(count)
52+
53+
# 오른쪽 팔
54+
count = 0
55+
for col in range(heart_col+1, N+1):
56+
if board[heart_row][col] == "*":
57+
count += 1
58+
else:
59+
break
60+
answer.append(count)
61+
62+
# 허리
63+
count = 0
64+
end_body = None
65+
for row in range(heart_row+1, N+1):
66+
if board[row][heart_col] == "*":
67+
count += 1
68+
else:
69+
end_body = [row-1,heart_col]
70+
break
71+
answer.append(count)
72+
# print(f"허리가 끝나는 지점 : {end_body}")
73+
74+
# 왼쪽 다리
75+
end_body_row, end_body_col = end_body
76+
77+
count = 0
78+
for row in range(end_body_row+1, N+1):
79+
if board[row][end_body_col-1] == "*":
80+
count += 1
81+
else:
82+
break
83+
answer.append(count)
84+
85+
# 오른쪽 다리
86+
count = 0
87+
for row in range(end_body_row+1, N+1):
88+
if board[row][end_body_col+1] == "*":
89+
count += 1
90+
else:
91+
break
92+
answer.append(count)
93+
94+
# 심장 위치 출력
95+
print(*heart)
96+
97+
# 왼쪽 팔, 오른쪽 팔, 허리, 왼쪽 다리, 오른쪽 다리의 길이
98+
print(*answer)

0 commit comments

Comments
 (0)