Algorithm/Problems_Solving
-
백준(BaekJoon) - 2501 약수구하기Algorithm/Problems_Solving 2022. 10. 10. 12:14
# 1st trial def func(n,k): result = [] for i in range(1,n+1): if n % i == 0: result.append(i) result.sort() if len(result) < k: return 0 return result[k-1] number, k = map(int, input().split()) func(number,k) # 2nd trial N, K = map(int, input().split()) result = 0 for i in range(1,N+1): if N % i == 0: K -= 1 if K == 0 : result = i break print(result) # 위의 식을 조만 변형해서?? N, K = map(int, input().spl..
-
백준(BaekJoon) 1924번 - 2007년Algorithm/Problems_Solving 2022. 10. 10. 11:13
# 처음에는 아래처럼.. 그냥 무식하게 하려고 했다.. 하다보니 이건 아닌듯 싶어서 quit def func(month, day): if month == 1 and day == 1 or month == 10: remainders = day % 7 if remainders == 0: return "Thurs" elif remainders == 1: return "Fri" elif remainders == 2: return "Sat" elif remainders == 3: return "Sun" elif remainders == 4: return "Mon" elif remainders == 5: return "Tue" elif remainders == 6: return "Wed" days_list = ["S..
-
프로그래머스(Programmers) LEVEL1 - 성격유형검사하기Algorithm/Problems_Solving 2022. 10. 9. 12:24
scores = {1:3, 2:2, 3:1, 4:0, 5:1, 6:2, 7:3} answer_report = {1: {"R":0, "T":0}, 2 :{"C":0, "F":0}, 3: {"J":0, "M":0}, 4: {"A":0, "N":0}, } def organization(answer): answer = {k : dict(sorted(v.items(), key=lambda x:(-x[1], x[0]))) for k, v in answer.items()} return "".join([list(v.keys())[0] for k, v in answer.items()]) def added_score(answer, result:dict) -> dict: for k, v in answer.items(): f..
-
프로그래머스(Programmers) LEVEL2 - 전화번호 목록Algorithm/Problems_Solving 2022. 10. 3. 10:58
# 1st def solution(phone_book): answer = True phone_book.sort(key=lambda x: len(x)) prefix = phone_book[0] # 이렇게 하면 안되는 이유가 만약에 prefix가 두번째 원소에는 해당되지 않고, 세번째 원소에 해당 되는 것이 있으면, 그래도 없는거로 해당이 되서 return이 끝난당 for ele in range(1,len(phone_book)): if prefix in phone_book[ele]: return False return True # return True의 위치만 for문을 다 끝내고 실행이 되도록 하자 def solution(phone_book): answer = True phone_book.sort(key=..
-
프로그래머스(Programmers) LEVEL2 - 위장Algorithm/Problems_Solving 2022. 10. 2. 12:39
def solution(clothes): dic= dict() for cloth in range(len(clothes)): if clothes[cloth][1] not in dic: dic[clothes[cloth][1]] = [clothes[cloth][0]] else: dic[clothes[cloth][1]].append(clothes[cloth][0]) val = len([item for values in dic.values() for item in values]) mul = 1 for v in dic.values(): mul = mul * len(v) if len(dic.keys()) == 1: return val else: return mul + val 정확성: 28.6 합계: 28.6 / 10..
-
프로그래머스(Programmers) LEVEL2 - JadenCase 문자열 만들기Algorithm/Problems_Solving 2022. 10. 2. 10:21
''' s.split() vs s.split(" ") ex) s = " 3people unFollowed me" s.split() 는 => ['3people', 'unFollowed', 'me'] s.split(" ")는 => ['', '', '3people', 'unFollowed', 'me'] ''' # 1st def solution(s): s = s.split(" ") return " ".join([strs[0].upper()+strs[1:].lower() if len(strs) > 0 else strs for strs in s]) # 다른사람풀이 def solution(s): s = s.split(" ") for i in range(len(s)): s[i] = s[i][:1].upper() + s..
-
프로그래머스(Programmers) LEVEL2 - 행렬의곱셈Algorithm/Problems_Solving 2022. 10. 1. 11:34
X = [[1, 2], [4, 5], [3, 6]] 3 x 2 matrix이다. 첫번째 row는 X[0] , 첫번째 row의 첫번째 element는 X[0][0] Y = [[1,2,3],[4,5,6]] 2 x 3 matrix이다 두 행렬을 곱한다고 했을 때 X의 coolumns와 Y의 rows가 같아야 한다 arr1 = [[12,7,3], [4,5,6],[7 ,8,9]] # 3x3 matrix arr2 = [[5,8,1,2],[6,7,3,0],[4,5,9,1]] # 3x4 matrix # 1st solution def solution(arr1, arr2): answer = [[0 for _ in range(len(arr2[0]))] for _ in range(len(arr1))] for i in rang..
-
프로그래머스(Programmers) LEVEL2 - 최댓값과 최솟값Algorithm/Problems_Solving 2022. 10. 1. 09:44
1. 최댓값과 최솟값 # 1st def solution(s): answer = '' min_num, max_num = min(s.split()), max(s.split()) if int(min_num) and int(max_num) >=0: return min_num + " " + max_num else: return max_num + " " + min_num 정확성: 16.7 합계: 16.7 / 100.0 = > s.split()하고 안에 요소들을 int로 바꿔주지 않았기 때문에 s = "-1 10 12 4"의 max 값의 경우 4가 나옴 # 2nd def solution(s): answer = '' s = list(map(int,s.split())) min_num, max_num = min(s), m..