Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 테이크스트라
- JazzMeet
- Spring
- 재즈밋
- MapSqlParameterSource
- 백준
- 코드스쿼드
- 채팅목록조회
- 회고
- 자유 프로젝트
- rotuter
- 231103
- BOJ
- 누구나 자료구조와 알고리즘
- Til
- NamedParameterJdbcTemplate
- 실패했지만성공했다
- Python
- Map.of()
- Paths.get()
- 오류
- baeldung
- 22년도
- 파이썬
- 2023
- 3주차 회고
- MAX
- 코드스쿼드max
- requested
- new File().toPath()
Archives
- Today
- Total
어제보다 한걸음 더
BOJ 백준 1063번, 킹 - Python 파이썬 본문
1063번: 킹
8*8크기의 체스판에 왕이 하나 있다. 킹의 현재 위치가 주어진다. 체스판에서 말의 위치는 다음과 같이 주어진다. 알파벳 하나와 숫자 하나로 이루어져 있는데, 알파벳은 열을 상징하고, 숫자는
www.acmicpc.net
문제: https://www.acmicpc.net/problem/1063
# 1063번 킹
import sys
def position_calculate(position, moves):
column_index = column.index(position[0]) + move_calculate_column(moves)
row_index = row.index(position[1]) + move_calculate_row(moves)
if (0 <= row_index < 8) and (0 <= column_index < 8): # 체스판 벗어나지 않는다면
return column[column_index] + row[row_index]
return position # 체스판 벗어난다면 원래 위치 그대로 출력
def move_calculate_column(moves):
if moves == 'R' or moves == 'RT' or moves == 'RB':
return 1
elif moves == 'L' or moves == 'LT' or moves == 'LB':
return -1
return 0
def move_calculate_row(moves):
if moves == 'B' or moves == 'RB' or moves == 'LB':
return -1
elif moves == 'T' or moves == 'RT' or moves == 'LT':
return 1
return 0
row = ['1', '2', '3', '4', '5', '6', '7', '8']
column = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
king_position, stone_position, n = input().split()
for i in range(0, int(n)):
move = input()
if position_calculate(king_position, move) == stone_position: # 이동한 king의 위치와 stone의 위치가 동일하다면
if stone_position != position_calculate(stone_position, move): # move만큼 이동한 돌의 위치가 체스판을 벗어나지 않는다면
king_position = position_calculate(king_position, move) # 킹의 위치 move 만큼 이동
stone_position = position_calculate(stone_position, move) # 돌의 위치도 move 만큼 이동
else:
king_position = position_calculate(king_position, move) # 킹의 위치 move 만큼 이동
print(king_position)
print(stone_position)
'Computer Science > Algorithm' 카테고리의 다른 글
BOJ 백준 14235번, 크리스마스 선물 - Python 파이썬 (0) | 2023.04.05 |
---|---|
BOJ 백준 13335번, 트럭 - Python 파이썬 (0) | 2023.04.05 |
BOJ 백준 1244번, 스위치 켜고 끄기 - Python 파이썬 (0) | 2023.03.28 |
BOJ 백준 1149번, RGB 거리 - Python 파이썬 (0) | 2023.03.28 |
BOJ 백준 2579번, 계단 오르기 - Python 파이썬 (0) | 2023.03.28 |