본문 바로가기

Python50

[백준] 그룹 단어 체커 / 1316번 / 파이썬 / Python 🎫code ) cnt = 0 for i in range(int(input())): word = input() word_lst = [word[0]] for k in range(1, len(word)): if word[k] != word[k - 1]: word_lst.append(word[k]) word_set = set(word_lst) if len(word_lst) == len(word_set): cnt += 1 print(cnt) 📌 description ) 문제출처 : www.acmicpc.net/problem/1316 1316번: 그룹 단어 체커 그룹 단어란 단어에 존재하는 모든 문자에 대해서, 각 문자가 연속해서 나타나는 경우만을 말한다. 예를 들면, ccazzzzbb는 c, a, z, b가 모두.. 2020. 11. 29.
[백준] 유기농배추 / 1012번 / 파이썬 / Python 🎫code ) for tc in range(1,int(input())+1): m, n, k = map(int,input().split()) arr = [[0]*m for _ in range(n)] stack = [] cnt = 0 dx = [-1,1,0,0] dy = [0,0,-1,1] for i in range(k): y, x = map(int,input().split()) arr[x][y] = 1 for i in range(m): for j in range(n): if arr[j][i] == 1: stack.append((j,i)) while stack: x, y = stack.pop() arr[x][y] = 2 for k in range(4): nx, ny = x+dx[k], y+dy[k] if 0 2020. 11. 28.
[백준] LCS / 9251번 / 파이썬 / Python / 최장 공통 부분수열 🎫code ) s1 = input() s2 = input() matrix = [[0] * (len(s2) + 1) for _ in range(len(s1) + 1)] for i in range(1, len(s1) + 1): for j in range(1, len(s2) + 1): if s1[i - 1] == s2[j - 1]: matrix[i][j] = matrix[i - 1][j - 1] + 1 else: matrix[i][j] = max(matrix[i - 1][j], matrix[i][j - 1]) print(matrix[-1][-1]) 📌 description ) 문제출처 www.acmicpc.net/problem/9251 9251번: LCS LCS(Longest Common Subsequence.. 2020. 11. 20.
[프로그래머스] 베스트앨범 / 파이썬 / Python / 해시 💫solutions ) 💬 defaultdict, heapq 모듈 사용 👩‍💻 code ) from collections import defaultdict import heapq def solution(genres, plays): gen = defaultdict(list) cnt = defaultdict(int) for i in range(len(genres)): heapq.heappush(gen[genres[i]], (-plays[i], i)) cnt[genres[i]] += plays[i] cnt_lst = [] for k, v in cnt.items(): cnt_lst.append((v, k)) cnt_lst.sort(key=lambda x: -x[0]) answer = [] count = 0 fo.. 2020. 11. 2.
[백준] 체스판 다시 칠하기 / 1018번 / 파이썬 / Python 🎫code ) import sys def chess(a, b, c): cnt = 0 for i in range(a, a + 8): for j in range(b, b + 8): if i == a and j == b: if c == 'W': chk = 'B' if bg[i][j] != c: cnt += 1 else: chk = 'W' if bg[i][j] != c: cnt += 1 continue if chk == 'W': if bg[i][j] != 'W': cnt += 1 chk = 'B' else: if bg[i][j] != 'B': cnt += 1 chk = 'W' if chk == 'W': chk = 'B' else: chk = 'W' return cnt input = sys.stdin.readli.. 2020. 10. 28.
[백준] 보물 / 1026번 / 파이썬 / Python 🎫code ) import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().rstrip().split(' '))) t_b = list(map(int, input().rstrip().split(' '))) b = [] for idx, val in enumerate(t_b): b.append((val, idx)) a.sort() b.sort(key=lambda x: -x[0]) res = 0 for i in range(n): tmp = a[i] * b[i][0] res += tmp print(res) 📌 description ) 문제출처 : www.acmicpc.net/problem/1026 1026번: 보물 첫째 줄에 N이.. 2020. 10. 27.