일반적으로 알고리즘 문제에서의 2차원 공간은 행렬(Matrix)의 의미로 사용됨
# 3행 5열
arr = [[0, 1, 2, 3, 4],
[5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]]
# arr[0] == 1행
# arr[0] -> [0, 1, 2, 3, 4]
# arr[1][2] == 2행 3열
# arr[0][2] == 7
시뮬레이션 및 완전 탐색 문제에서는 2차원 공간에서의 방향 벡터가 자주 활용됨
# 동, 북, 서, 남
dx = [0, -1, 0, 1]
dy = [1, 0, -1, 0]
# 현재 위치
x, y = 2, 2
# 동, 북, 서, 남 이동
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
print(nx, ny)
# 상하좌우
x, y = 1, 1
# 입력
n = int(input())
plan = list(input().split())
for direction in plan:
if direction == 'R' and y < n:
y += 1
elif direction == 'L' and y > 1:
y -= 1
elif direction == 'U' and x > 1:
x -= 1
elif direction == 'D' and x < n:
x += 1
print(x, y)
# 상하좌우
n = int(input())
x, y = 1, 1
plans = input().split()
# L, R, U, D
dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]
move_types = ['L', 'R', 'U', 'D']
for plan in plans:
for i in range(len(move_types)):
if plan == move_types[i]:
nx = x + dx[i]
ny = y + dy[i]
if nx < 1 or ny < 1 or nx > n or ny > n:
continue
x, y = nx, ny
print(x, y)
# 시각
# n 입력
n = int(input())
# 시간에 3이 없는 경우 1시간 동안 1575번 카운트 (15 * 60 + 45 * 15)
# 시간에 3이 있는 경우 1시간 동안 3600번 카운트
if n < 3:
# n : 0, 1, 2
count = (n + 1) * 1575
elif n < 13:
# n : 3 ~ 12
count = 3600 + n * 1575
elif n < 23:
# n : 13 ~ 22
count = 3600 * 2 + (n - 1) * 1575
else:
# n : 23
count = 3600 * 3 + 21 * 1575
print(count)
# 시각
h = int(input())
count = 0
for i in range(h + 1):
for j in range(60):
for k in range(60):
if '3' in str(i) + str(j) + str(k):
count += 1
print(count)
# 왕실의 나이트
# 입력
position = input()
row = int(position[1])
column = ord(position[0]) - 96
# 이동
# 8가지 이동의 경우의 수
drow = [-2, -2, -1, -1, +2, +2, +1, +1]
dcolumn = [+1, -1, +2, -2, -1, +1, -2, +2]
# count
count = 0
for i in range(8):
new_row = row + drow[i]
new_column = column + dcolumn[i]
if new_row in range(1, 9) and new_column in range(1, 9):
count += 1
print(count)
# 단어 공부
str = input()
str = str.upper()
letter_count = -1
for letter in set(str):
if letter_count == str.count(letter):
output = '?'
elif letter_count < str.count(letter):
output = letter
letter_count = str.count(letter)
print(output)
str = str.upper()
: 대소문자를 구분하지 않기 때문에 문자열 메소드를 이용하여 모든 문자를 대문자로 변경letter_count
: 최빈 문자의 개수를 저장하는 변수for letter in set(str)
: set 자료형을 이용하여 입력된 문자열의 문자 목록을 반환하게 함str.count(letter)
: 문자열의 count메소드를 이용하여 문자의 개수 카운트# 숫자의 개수
digit_list = [0] * 10
# 입력
a = int(input())
b = int(input())
c = int(input())
products = a * b * c
for char in str(products):
digit_list[int(char)] += 1
for digit in digit_list:
print(digit)
좋은 내용 잘 읽고 갑니다