본문 바로가기

python-algorithm1402

백준 18141 Are They All Integers? https://www.acmicpc.net/problem/18141 18141번: Are They All Integers? Computing using integers is a dream for every programmer. That is, you do not have to deal with floating point numbers, estimated errors, and etc. We do not even need any floating point units in our computers for divisions! Your company claimed there is a www.acmicpc.net 1234567891011121314from itertools import permutationsdef .. 2023. 11. 28.
백준 15122 Forbidden Zero https://www.acmicpc.net/problem/15122 15122번: Forbidden Zero You’re writing the positive integers in increasing order starting from one. But you’ve never learned the digit zero, and thus omit any number that contains a zero in any position. The first ten integers you write are: 1, 2, 3, 4, 5, 6, 7, 8, 9, and 11. www.acmicpc.net 123456789def solution(s): s = str(int(s) + 1) return s.replace('0','.. 2023. 11. 28.
백준 16283 Farm https://www.acmicpc.net/problem/16283 16283번: Farm 입력은 표준입력을 사용한다. 첫 번째 줄에 네 정수 a, b, n, w가 한 줄에 주어진다. 1 ≤ a ≤ 1,000, 1 ≤ b ≤ 1,000, 2 ≤ n ≤ 1,000, 2 ≤ w ≤ 1,000,000이다. www.acmicpc.net 1234567891011121314151617def solution(a, b, n, w): answer = [] for x in range(1, n): if a * x + (n - x) * b == w: answer.append((x, n - x)) if len(answer) == 1: return answer[0] else: return [-1] if __name__ == '_.. 2023. 11. 28.
백준 1440 타임머신 https://www.acmicpc.net/problem/1440 1440번: 타임머신 첫째 줄에 시간이 주어진다. 시간은 DD:DD:DD와 같은 꼴로 주어진다. 항상 8자리(:도 포함)로만 들어오며, D는 0-9 사이의 숫자이다. www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 from itertools import permutations def check(nums): if 1 2023. 11. 28.
백준 19564 반복 https://www.acmicpc.net/problem/19564 19564번: 반복 muse가 입력하고자 하는 글 $S$가 주어진다. 이 글은 알파벳 소문자만으로 이루어져 있으며, 길이는 $L$이다. ($1 \le L \le 10^5$) www.acmicpc.net 1234567891011121314def solution(s): answer = 1 for i in range(1, len(s)): if ord(s[i]) 2023. 11. 27.
백준 30700 KOREA 문자열 만들기 https://www.acmicpc.net/problem/30700 30700번: KOREA 문자열 만들기 첫 번째 줄에 문자열 $S$가 주어진다. $S$는 영어 알파벳 대문자 K, O, R, E, A로만 이루어져 있으며, 문자열의 길이는 $10$ 이상 $1\,000$ 이하이다. www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 def solution(s): korea = ['K','O',"R",'E',"A"] current, answer = 0, 0 for i in s: if i == korea[current]: answer += 1 current = (current + 1) % 5 return answer if __name__ == '__main__': s .. 2023. 11. 27.
백준 28062 준석이의 사탕 사기 https://www.acmicpc.net/problem/28062 28062번: 준석이의 사탕 사기 준석이는 두 동생을 위해 사탕 가게에서 사탕을 최대한 많이 사 가려고 한다. 사탕 가게에는 $N$개의 사탕 묶음이 있으며 $i$번째 사탕 묶음에는 $a_i$개의 사탕이 있다. 준석이는 정말 부자라 사탕 www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 def solution(nums): answer = 0 odd_nums = [] for num in nums: if num % 2 == 0 : answer += num else: odd_nums.append(num) odd_nums.sort(reverse= True) answer += s.. 2023. 11. 27.
백준 26529 Bunnies https://www.acmicpc.net/problem/26529 26529번: Bunnies You’re going to raise farm animals and you decided to start with bunnies, the easiest of animals. To your surprise they are breeding like rabbits, so much so that you’re unable to count them accurately. However, you know that rabbits’ breeding patter www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 def solution(n): answer = [1, 1] for i in ra.. 2023. 11. 25.
백준 15841 Virus Outbreak https://www.acmicpc.net/problem/15841 15841번: Virus Outbreak For each input value, the output contains a line in the format: Hour X: Y cow(s) affected, where X is the hour, and Y is the total affected cows that need to be euthanized based on the hour given by X. www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 def solution(n): answer = [0, 1, 1] for i in range(3, n + 1): answer.append(answer[-1].. 2023. 11. 25.
백준 29738 Goodbye, Code Jam https://www.acmicpc.net/problem/29738 29738번: Goodbye, Code Jam Round 1은 Round 1A, Round 1B, Round 1C로 이루어진 $3$개의 라운드 중 $1$개의 라운드에서 상위 $1\,500$등 안에 들면 다음 라운드로 진출하는 방식이나 문제에서는 서술 편의상 $4\,500$등으로 표현했다. www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 def solution(n): if n 2023. 11. 23.
백준 30676 이 별은 무슨 색일까 https://www.acmicpc.net/problem/30676 30676번: 이 별은 무슨 색일까 별의 색을 출력한다. 빨간색이면 "Red", 주황색이면 "Orange", 노란색이면 "Yellow", 초록색이면 "Green", 파란색이면 "Blue", 남색이면 "Indigo", 보라색이면 "Violet"을 출력한다. www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 def solution(n): if 620 2023. 11. 23.
백준 30033 Rust Study https://www.acmicpc.net/problem/30033 30033번: Rust Study 첫 번째 줄에는 임스가 계획하고 공부한 일수 $N$이 주어진다. $(1 \le N \le 1\,000)$ 두 번째 줄에는 임스가 공부하고자 계획한 페이지 수 $A_1$, $A_2$, $\cdots$, $A_N$가 공백으로 구분되어 주어진다. $(1 \le www.acmicpc.net 1234567891011121314def solution(a, b): answer = 0 for an, bn in zip(a,b): if an 2023. 11. 16.