[백준/파이썬] 13240번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 13240번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
Write a program that prints a chessboard with N rows and M columns with the following rules:
-
The top left cell must be an asterisk (*)
-
Any cell touching (left, right, up or down) a cell with an asterisk must be a dot (.)
-
Any cell touching (left, right, up or down) a cell with a dot must be an asterisk.
A chessboard of 8 rows and 8 columns printed using these rules would be:
.... .... .... .... .... .... .... ....
입력 요약
A single line with two integers N and M separated by spaces. The number N will represent the number of rows and M the number of columns. N and M will be between 1 and 10.
출력 요약
Print N lines each containing M characters with the chessboard pattern.
코드
n,m=map(int,input().split())
l=[['*'if (i+j)%2==0 else'.'for j in range(m)]for i in range(n)]
r=''
for row in l:r+=''.join(row)+'\n'
print(r)
설명
핵심은 구현 관점에서 Write a program that prints a chessboard with N rows and M columns with the following rules:
- The top left cell must be an asterisk (*) …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기