Algorithm/Problems 92

[백준/파이썬] 2738번 행렬 덧셈

https://www.acmicpc.net/problem/2738 2738번: 행렬 덧셈 첫째 줄에 행렬의 크기 N 과 M이 주어진다. 둘째 줄부터 N개의 줄에 행렬 A의 원소 M개가 차례대로 주어진다. 이어서 N개의 줄에 행렬 B의 원소 M개가 차례대로 주어진다. N과 M은 100보다 작거나 같 www.acmicpc.net n, m = map(int, input().split()) A, B = [], [] for i in range(n): a = list(map(int, input().split())) A.append(a) for i in range(n): b = list(map(int, input().split())) B.append(b) sum = 0 for i in range(n): for j i..

Algorithm/Problems 2022.11.07

[프로그래머스] 위장 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/42578 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr from itertools import combinations def solution(clothes): cb = [] tmp = [] for i in range(len(clothes)): tmp.append(clothes[i][1]) for i in range(len(set(tmp))): cb.append(list(combinations(tmp,i))) if len(set(tmp)) == 1: r..

Algorithm/Problems 2022.11.02

[프로그래머스] 전화번호 목록 Python

https://school.programmers.co.kr/learn/courses/30/lessons/42577 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내가 짠 코드 😥 def solution(phone_book): answer = True sorted(phone_book) for i in range(len(phone_book)): for j in range(1, len(phone_book)): if len(phone_book[i]) < len(phone_book[j]): if phone_book[i] in phone_book[j][:len(ph..

Algorithm/Problems 2022.10.28

[프로그래머스] 폰켓몬 python

https://school.programmers.co.kr/learn/courses/30/lessons/1845 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import numpy as np def solution(nums): num = np.unique(nums) if (len(nums)/2) len(num): answer = len(num) return answer 엉망진창 내가 짠 코드😥 numpy 모듈 중 unique() 함수를 사용하여 주어진 배열에서 고유값만 리턴해주었다. 이때, 내가 데려갈 수 있는 폰켓몬 수가 더 크다면 고유값의 수를 리턴..

Algorithm/Problems 2022.10.26

[프로그래머스] 완주하지 못한 선수

https://school.programmers.co.kr/learn/courses/30/lessons/42576 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(participant, completion): answer='' for idx, p in enumerate(participant): if p in completion: continue else: answer = participant[idx] return answer 아무생각 없이 짠 내 코드😥 이름이 같은 사람이 여러명 있고 그 중 한사람만 완주하는 경우에는 이 코드가 적용..

Algorithm/Problems 2022.10.26

[프로그래머스] K번째 수

문제 url: https://school.programmers.co.kr/learn/courses/30/lessons/42748?language=python3 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(array, commands): answer = [] for com in commands: arr = array[com[0]-1:com[1]] arr.sort() answer.append(arr[com[2]-1]) return answer def solution(array, commands): return list(map(lamb..

Algorithm/Problems 2022.08.21

[프로그래머스] 체육복 (탐욕법 Greedy)

문제 url: https://school.programmers.co.kr/learn/courses/30/lessons/42862 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(n, lost, reserve): # 오름차순으로 정렬 lost.sort() reserve.sort() # 차집합을 이용해 여벌옷이 있는데 도난당했을 경우 제외 new_lost = set(lost) - set(reserve) new_reserve = set(reserve) - set(lost) for r in new_reserve: if r - 1 in new..

Algorithm/Problems 2022.08.16

[백준] 2675번 문자열 반복

문제 링크: https://www.acmicpc.net/problem/2675 2675번: 문자열 반복 문자열 S를 입력받은 후에, 각 문자를 R번 반복해 새 문자열 P를 만든 후 출력하는 프로그램을 작성하시오. 즉, 첫 번째 문자를 R번 반복하고, 두 번째 문자를 R번 반복하는 식으로 P를 만들면 된다 www.acmicpc.net n = int(input()) for i in range(n): str = input().split() list_s = list(str[1]) num = int(str[0]) # 각 문자 반복 횟수 for j in range(len(list_s)): for k in range(num): print(list_s[j], end="") print() 문자열이 입력된 것을 list로..

Algorithm/Problems 2022.08.11

[프로그래머스] 타겟 넘버 (DFS/BFS)

코딩테스트 공부하기로 마음먹고 처음 풀어본 문제다. 하지만.. 결과는 처.참.했.다. 검색을 해보니 DFS/BFS 문제로 푼다고 한다. 둘 중 스택을 이용한 DFS로 풀이 하는 것으로 이해했고 풀이했다. 문제 2번째 예시인 numbers가 [4,1,2,1] 인 경우를 생각해봤다. def solution(numbers, target): answer = 0 n = len(numbers) # temp, idx 값을 의미 stack = [[numbers[0], 0], [-1*numbers[0], 0]] while stack: temp, idx = stack.pop() idx += 1 if idx < n: stack.append([temp+numbers[idx], idx]) stack.append([temp-nu..

Algorithm/Problems 2022.08.02