๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
728x90
๋ฐ˜์‘ํ˜•

์•Œ๊ณ ๋ฆฌ์ฆ˜ ๐Ÿ’ก/๋ฐฑ์ค€2

๋ฐฑ์ค€ 7576๋ฒˆ ํ† ๋งˆํ†  (BFS ๋ฌธ์ œ) _ ํŒŒ์ด์ฌ from collections import deque# ์ž…๋ ฅ ๋ฐ›๊ธฐM, N = map(int, input().split())tomato = [list(map(int, input().split())) for _ in range(N)]# 4๋ฐฉํ–ฅ(์ƒ, ํ•˜, ์ขŒ, ์šฐ) ์ •์˜dx = [-1, 1, 0, 0]dy = [0, 0, -1, 1]# ์ต์€ ํ† ๋งˆํ† ์˜ ์œ„์น˜ ํ์— ๋„ฃ๊ธฐqueue = deque()# ์ดˆ๊ธฐ ์ต์€ ํ† ๋งˆํ†  ์œ„์น˜ ์ฐพ๊ธฐfor i in range(N): for j in range(M): if tomato[i][j] == 1: # ์ต์€ ํ† ๋งˆํ† ์ผ ๊ฒฝ์šฐ queue.append((i, j))# BFS ์‹œ์ž‘def bfs(): # ํ๊ฐ€ ๋นŒ ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณต while queu.. 2025. 2. 18.
1181.๋‹จ์–ด ์ •๋ ฌ.py # 20230818 import sys sys.stdin=open("input.txt","r") n = int(input()) # ๋‹จ์–ด์˜ ๊ฐœ์ˆ˜๋ฅผ ์ž…๋ ฅ ๋ฐ›๊ณ  word = [] # word ๋ฅผ ๋ฆฌ์ŠคํŠธ๋กœ ์„ค์ • for i in range(n): # n ๋ฒˆ ๋งŒํผ for ๋ฌธ์œผ๋กœ ๋‹จ์–ด๋“ค์„ ์ถ”๊ฐ€(append) word.append(input()) set_word = list(set(word)) # ์ค‘๋ณต์„ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š” set์˜ ํŠน์„ฑ(์ค‘๋ณต์ œ๊ฑฐ)- ํ•˜์ง€๋งŒ ์ˆœ์„œ๋Š” ๋’ค์ฃฝ๋ฐ•์ฃฝ์ด๋‹ค. print(set_word) sort_word = [] # ์ •๋ ฌํ•œ ๋‹จ์–ด๋ฅผ ์ €์žฅํ•ด์ค„ ๋ฆฌ์ŠคํŠธ sort_word ๋ณ€์ˆ˜ for i in set_word: # ๋ฆฌ์ŠคํŠธ set_word ๋ฅผ ํ•˜๋‚˜์”ฉ i ์— ๋„ฃ์œผ๋ฉด์„œ ๋ฐ˜๋ณต sort_word.append((len(i).. 2023. 8. 9.
728x90
๋ฐ˜์‘ํ˜•