문제 링크 10205번: 헤라클레스와 히드라 헤라클레스는 그리스 신화의 유명한 비극적인 영웅이다. 그는 제우스의 사생아로 태어났는데, 이때문에 제우스의 아내 헤라는 그를 매우 싫어했다. 그는 매우 강한 힘과 높은 지식을 가졌지만, www.acmicpc.net 문제 풀이 머리의 수가 h로 주어지고, 문자열이 주어질 때, 문자열 중 문자가 c일 경우 머리를 자르고 2개가 다시 자라나므로 h + 1이 되고, 문자가 b일 경우에는 다시 자라나지 않으므로 h - 1이 된다. 이 규칙으로 반복문을 구현했다. 정답 코드 for n in range(1, int(input()) + 1) : h = int(input()) for i in input() : if i == "c" : h += 1 else : h -= 1 pr..
문제 링크 10187번: Golden There are many special irrational numbers in nature. One is the “golden ratio” represented by the Greek letter phi, φ, which has a value of φ = (1 + √5) / 2 = 1.61803399..... Given 2 real numbers, determine whether their ratio is equal (or close to www.acmicpc.net 문제 풀이 주어진 황금비율과 1%의 오차 범위 내에 입력값이 해당된다면, "golden"을 출력하고, 아니라면 "not"을 출력한다. 정답 코드 gold = 1.61803399 dif = gold * ..
문제 링크 9950번: Rectangles Input is a series of lines, each containing 3 integers, l, w, and a ( 0 ≤ l w ≤100, 0 ≤ a ≤ 10,000) representing the length, width and area of a rectangle in that order. The integers are separated by a single space. In each row, only one of the val www.acmicpc.net 문제 풀이 입력값에 0의 위치에 따른 빈칸의 값을 채워 출력해준다. 정답 코드 while True : a, b, c = map(int, input().split()) if a == b == c =..
문제 링크 9924번: The Euclidean Algorithm The famous Euclidean algorithm is found in Book VII of the Elements. The Elements was written in 300 B.C.~by the Greek mathematician Euclid. It is rumored that King Ptolemy, having looked through the Elements, hopefully asked Euclid if there were not a sho www.acmicpc.net 문제 풀이 A, B가 주어졌을 때, 특정한 계산을 통해 B가 0이 될 때 까지의 반복문 수행 횟수를 구해준다. 정답 코드 def solve(A, B, n) :..
문제 링크 9907번: ID The National Identity Card number of the city state of Eropagnis, NICE, consists of seven digits and a letter appended behind. This letter is calculated from the digits using the Modulo Eleven method. The steps involved in the computation are as follows: www.acmicpc.net 문제 풀이 문제에 주어진대로 입력값의 각 자릿수마다 숫자를 곱해준 뒤, 그 합을 11로 나눈 나머지를 "JABCDEFHIZ"의 인덱스로 매핑한다. 정답 코드 id_map = "JABCDEFGHIZ" ..
문제 링크 9848번: Gift The first line contains 2 integers n and k, where n (3 ≤ n ≤ 100) is the number of days, and k (0 < k ≤ 100,000) the desired improvement (in milliseconds). Whenever Jacqueline’s timing reduces by at least k milliseconds over the previous day’s ti www.acmicpc.net 문제 풀이 첫 줄에 주어진 K를 가지고 각각의 입력값을 전 입력값과 비교했을 때 차이가 K이상일 경우의 수를 구해 출력한다. 정답 코드 n, K = map(int, input().split()) ans = 0 ..
문제 링크 9838번: XMAS Your program must write a mapping from the guests to the recipients of their gifts to the standard output. The first line contains an integer indicating the recipient of the gift brought by guest 1. Similarly, the second line contains an integer indicating www.acmicpc.net 문제 풀이 입력된 값을 인덱스로, 들어온 순서를 값으로 정해준 뒤, 순서대로 출력해준다. 정답 코드 n = int(input()) lst = [0] * (n + 1) for i in range..
문제 링크 9783번: Easy Encryption In order to send a secret message to your friend, you invent an original method to encrypt the message. The encryption rule is quite simple. A letter is replaced with 2-digit number. Each letter has its corresponding number as the following: a = 01, b = 02 www.acmicpc.net 문제 풀이 입력값을 문제의 규칙에 따라 변환해 출력해주는 문제이다. 알파벳은 소문자 a부터 z까지 01 ~ 26으로 변환해 출력해준다. 대문자는 A ~ Z 까지 27 ~ 5..