구현 15

백준 14719번 빗물 파이썬

https://www.acmicpc.net/problem/14719 14719번: 빗물 첫 번째 줄에는 2차원 세계의 세로 길이 H과 2차원 세계의 가로 길이 W가 주어진다. (1 ≤ H, W ≤ 500) 두 번째 줄에는 블록이 쌓인 높이를 의미하는 0이상 H이하의 정수가 2차원 세계의 맨 왼쪽 위치 www.acmicpc.net 내 코드 h, w = map(int, input().split()) blocks = list(map(int, input().split())) result = 0 for i in range(1, w-1): left_max = max(blocks[:i]) right_max = max(blocks[i+1:]) standard = min(left_max, right_max) depth ..

BOJ/Python 2024.03.19

[프로그래머스] 키패드 누르기 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/67256 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 보기 더보기 내 코드 def judge(start, end): keypad = { '1': (0, 0), '2': (0, 1), '3': (0, 2), '4': (1, 0), '5': (1, 1), '6': (1, 2), '7': (2, 0), '8': (2, 1), '9': (2, 2), '*': (3, 0), '0': (3, 1), '#': (3, 2) } start_distance = ..

BOJ/Python 2023.11.24

[프로그래머스] 신고 결과 받기 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/92334 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 보기 더보기 내 코드 from collections import defaultdict def solution(id_list, report, k): answer = [0] * len(id_list) report_count = defaultdict(int) for i in set(report): report_count[i.split()[1]] += 1 filtered_set = {key for ..

BOJ/Python 2023.11.20

[프로그래머스] [1차] 캐시

https://school.programmers.co.kr/learn/courses/30/lessons/17680 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 # 1차 캐시 from collections import deque def solution(cacheSize, cities): cache = deque([]) cities = map(lambda x: x.lower(), cities) # 모두 소문자로 구분 hit = 1 miss = 5 result = 0 for i in cities: if not i in cache and len(cac..

프로그래머스 2023.06.02

[프로그래머스] 괄호 변환 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/60058 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def isComplete(s): result = 0 for j in s: if j == '(': result += 1 else: result -= 1 if result < 0: break if result == 0: return True else: return False def solution(p): global answer # 1. 입력이 빈 문자열인 경우, 빈 문자열을 반환합니다. ..

프로그래머스 2023.05.30

[프로그래머스] 평행 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/120875 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def gradient(a, b): # 기울기 계산 return (a[1] - b[1]) / (a[0] - b[0]) def solution(dots): p1, p2, p3, p4 = dots[:4] if gradient(p3, p1) == gradient(p4, p2) or gradient(p4, p3) == gradient(p2, p1): return 1 else: return 0 ..

프로그래머스 2023.02.01

[프로그래머스] 옹알이 (1) 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/120956 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def solution(babbling): result = 0 for i in babbling: cnt = 0 word = '' for j in i: word += j if word in ['aya', 'ye', 'woo', 'ma']: word = '' cnt += 1 if len(word) == 0 and cnt > 0: result += 1 return result Review 문..

프로그래머스 2023.02.01

백준 25305번 커트라인 파이썬

https://www.acmicpc.net/problem/25305 25305번: 커트라인 시험 응시자들 가운데 1등은 100점, 2등은 98점, 3등은 93점이다. 2등까지 상을 받으므로 커트라인은 98점이다. www.acmicpc.net 내 답안 import sys input = sys.stdin.readline N, K = map(int, input().split()) score = sorted(list(map(int, input().split()))) print(score[N-K]) Review 이 문제는 구현과, 정렬 보다는 N, K = map(int, input().split()) score = sorted(list(map(int, input().split()))) 입력을 어떤 식으로 받는지가..

BOJ/Python 2023.01.19

백준 1138번 한 줄로 서기 파이썬

https://www.acmicpc.net/problem/1138 1138번: 한 줄로 서기 첫째 줄에 사람의 수 N이 주어진다. N은 10보다 작거나 같은 자연수이다. 둘째 줄에는 키가 1인 사람부터 차례대로 자기보다 키가 큰 사람이 왼쪽에 몇 명이 있었는지 주어진다. i번째 수는 0보다 www.acmicpc.net 내 답안 N = int(input()) x = list(map(int, input().split())) d = [0] * N for i in range(N): for j in range(N): if x[i] == 0 and d[j] == 0: d[j] = i + 1# i 가 0 부터 시작하니 + 1을 해줌 break elif d[j] == 0: x[i] -= 1 print(' '.join(..

BOJ/Python 2022.06.28

백준 1259번 팰린드롬수 파이썬

https://www.acmicpc.net/problem/1259 1259번: 팰린드롬수 입력은 여러 개의 테스트 케이스로 이루어져 있으며, 각 줄마다 1 이상 99999 이하의 정수가 주어진다. 입력의 마지막 줄에는 0이 주어지며, 이 줄은 문제에 포함되지 않는다. www.acmicpc.net 내 답안 import sys input = sys.stdin.readline while True: x = input().rstrip() if x == '0': break else: cnt = 0 l = len(x) // 2 for i in range(l): if x[i] == x[-(i + 1)]: # 순차적으로 탐색 cnt += 1 if l == cnt: print('yes') else: print('no') ..

BOJ/Python 2022.03.29