일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- realclass
- 화상영어
- Daily Challenge
- 쓰릴오브파이트
- Problem Solving
- 스탭퍼
- 리얼 클래스
- 미드시청
- 링피트
- Writing
- 잡생각
- 괜찮음
- 3줄정리
- 프로젝트
- 사이드
- 매일
- FIT XR
- 개발자
- 영어공부
- 읽기
- leetcode
- 운동
- 만화도
- 10분
- 파비최
- 뭐든
- 영어원서읽기
- English
- 월간
- 30분
Archives
- Today
- Total
파비의 매일매일 공부기록
[BOJ] 1996 본문
https://www.acmicpc.net/problem/1996
1996번: 지뢰 찾기
첫째 줄에 N(1 ≤ N ≤ 1,000)이 주어진다. 다음 N개의 줄에는 지뢰 찾기 map에 대한 정보가 주어지는데 '.' 또는 숫자로 이루어진 문자열이 들어온다. '.'는 지뢰가 없는 것이고 숫자는 지뢰가 있는 경
www.acmicpc.net
주어진 조건대로 구현하면 됨.
딱히 어려운 건 없었으나, 문자(*, M) 출력이 조금 번거로웠음.
import sys
input = sys.stdin.readline
pos_x = [0, 1, 1, 1, 0, -1, -1, -1]
pos_y = [-1, -1, 0, 1, 1, 1, 0, -1]
n = int(input())
board = []
for _ in range(n):
board.append(list(input()))
res = [[0 for _ in range(n)] for __ in range(n)]
def fill_mines(board, x, y):
if board[y][x] == '.':
return
v = int(board[y][x])
for i in range(8):
if x + pos_x[i] < 0 or y + pos_y[i] < 0 or x + pos_x[i] >= n or y + pos_y[i] >= n:
continue
res[y + pos_y[i]][x + pos_x[i]] += v
for y in range(n):
for x in range(n):
fill_mines(board, x, y)
for y in range(n):
for x in range(n):
if board[y][x] != '.':
res[y][x] = '*'
else:
if int(res[y][x]) > 9:
res[y][x] = 'M'
print(res[y][x], end='')
print('')
반응형
'Problem Solving > BOJ' 카테고리의 다른 글
[BOJ] 2028 (0) | 2022.04.10 |
---|---|
[BOJ] 2010 (0) | 2022.04.09 |
[BOJ] 1977 (0) | 2022.04.07 |
[BOJ] 1975 (0) | 2022.04.06 |
[BOJ] 1964 [재시도 필요] (0) | 2022.04.05 |
Comments