본문 바로가기
반응형

프로그래머스/1단계83

(Python/LV1) 비밀지도 문제 출처: https://school.programmers.co.kr/learn/courses/30/lessons/17681 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이: def solution(n, arr1, arr2): answer = [] for i in range(n): tmp = bin(arr1[i] or arr2[i]) print(tmp) tmp = tmp[2:].zfill(n) # 앞에 두개 짜르고 뒤에 n 자릿수 만큼만큼 0 차운다 tmp = tmp.replace('1','#').replace('0',' ') answer.appen.. 2022. 9. 11.
(Python/LV1) 시저 암호 문제 출처: https://school.programmers.co.kr/learn/courses/30/lessons/12926 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이: def solution(s, n): s = list(s) for i in range(len(s)): print(s[i]) if s[i].isupper(): s[i]=chr((ord(s[i])-ord('A')+ n) % 26 + ord('A')) elif s[i].islower(): s[i]=chr((ord(s[i])-ord('a')+ n) % 26 + ord('a')) retu.. 2022. 9. 11.
(Python/LV1) 예산 문제 출처: https://school.programmers.co.kr/learn/courses/30/lessons/12982 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이: def solution(d, budget): d.sort() res = 0 for i in d : budget -= i if budget < 0 : break res += 1 return res 풀이 2: def solution(d, budget): d.sort() while budget < sum(d): d.pop() return(len(d)) 처음엔 combination 을.. 2022. 9. 11.
(Python/LV1) 3진법 뒤집기 문제 출처: https://school.programmers.co.kr/learn/courses/30/lessons/68935 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이: def solution(n): answer = '' while n >= 1: n, remainder = divmod(n, 3) answer += str(remainder) answer = int(answer,3) return answer 다른 비슷한 풀이: def solution(n): tmp = '' while n: tmp += str(n % 3) n = n // 3 answ.. 2022. 9. 11.
(Python/LV1) 이상한 문자 만들기 문제 출처: https://school.programmers.co.kr/learn/courses/30/lessons/12930 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 틀린 풀이: def solution(s): return "".join([i.upper() if s.index(i) % 2 == 0 else i for i in s]) # 이렇게 하니 find 에서 L을 찾으면 뒤에 L 까지 바뀌어서 안된다., 풀이: def solution(s) return ' '.join([''.join([b.upper() if a % 2 == 0 else b.low.. 2022. 9. 11.
(Python/LV1) 최대공약수와 최소공배수 문제 출처: https://school.programmers.co.kr/learn/courses/30/lessons/12940 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이: def solution(x, y): max_xy = max(x, y) min_xy = min(x, y) res= [] # 최대 공약수 while y > 0: x, y = y, x % y res = [x, max_xy * min_xy//x] return res 유클리드 호제법을 사용하면 된다. https://windy7271.tistory.com/122 (Python/🥈5)백준 .. 2022. 9. 11.
반응형