문제풀이/백준(Boj) 문제풀이 188

[백준][BFS] 1753. 최단경로 (파이썬/Python)

import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) import heapq n, m = map(int, input().split()) start = int(input()) INF = int(1e9) graph = [[] * (n+1) for _ in range(n+1)] distance = [INF] * (n+1) for _ in range(m): u, v, w = map(int, input().split()) # u에서 v로 가는 거리가 w라는 의미 graph[u].append((v, w)) def dijkstra(start): q = [] heapq.heappush(q, (0, start)) distance[start] = 0 whi..

[백준][큐 & 덱] 18258. 큐 2 (파이썬/Python)

import sys input = sys.stdin.readline def push(x): return queue.append(x) def pop(): if len(queue) > 0: return queue.pop(0) return -1 def size(): return len(queue) def empty(): if len(queue) > 0: return 0 return 1 def front(): if len(queue) > 0: return queue[0] return -1 def back(): if len(queue) > 0: return queue[-1] return -1 n = int(input()) queue = [] for _ in range(n): command = input().spl..

[백준][구현] 2504.괄호의 값 (파이썬/Python)

s = input() def is_check(s): # 올바른 괄호열인지 확인하는 함수 stack = [] flag = True for i in range(len(s)): if s[i] == '(' or s[i] == '[': stack.append(s[i]) else: # ) ] if s[i] == ')': if stack and stack[-1] == '(': stack.pop() else: flag = False else: # ] if stack and stack[-1] == '[': stack.pop() else: flag = False if not stack and flag: return True return False def calc_value(s): # 괄호의 값을 계산하는 함수 stack ..

[백준][구현] 10820. 문자열 분석 (파이썬/Python)

import sys input = sys.stdin.readline a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" b = "abcdefghijklmnopqrstuvwxyz" num = "1234567890" while True: s = input().rstrip('\n') A=B=SPACE=NUM = 0 if not s: break for i in s: if i in a: A+=1 elif i in b: B+=1 elif i in num: NUM+=1 else: SPACE +=1 print(f"{B} {A} {NUM} {SPACE}") https://suri78.tistory.com/111 [백준알고리즘] 10820번: 문자열 분석 -Python [백준알고리즘] 10820번: 문자열 분석 -..

[백준][구현] 11723. 집합 (파이썬/Python)

import sys input = sys.stdin.readline set_lst = set() def add(x): set_lst.add(x) def remove(x): set_lst.discard(x) def check(x): if x in set_lst: return 1 return 0 def toggle(x): if x in set_lst: set_lst.discard(x) else: set_lst.add(x) def set_all(): global set_lst set_lst = {i for i in range(1, 21)} def empty(): set_lst.clear() for _ in range(int(input())): command = input().split() if command[..