문제 링크 6131번: 완전 제곱수 상근이는 선영이와 함께 게임을 하고 있다. 먼저, 상근이는 두 양의 정수 A와 B를 고른다. (1 ≤ B ≤ A ≤ 500) 그 다음, 선영이는 상근이가 고른 수를 맞춰야 한다. 상근이는 선영이에게 다음과 같 www.acmicpc.net 문제 풀이 반복문에 규칙을 정해서 문제의 조건을 찾아나간다. 규칙은 다음과 같다. b^2 - a^2 == N인 경우, 정답이 1 증가하고, b가 1 증가한다. b^2 - a^2 N인 경우, a가 1 증가한다. 규칙 1에서 정답이 1 증가한 뒤 b를 증가시키는 이유는 다음 정답을 찾기 위함이다. 정답 코드 N = int(input()) a, b, ans = 1, 2, 0 while..
문제 링크 6030번: Scavenger Hunt Farmer John has scattered treats for Bessie at special places in the pasture. Since everyone knows that smart cows make tasty milk, FJ has placed the treats at locations that require Bessie to think. He has given her two numbers, P and Q (1
문제 링크 5789번: 한다 안한다 첫째 줄에는 테스트 케이스의 개수 N이 주어진다. (1 ≤ N ≤ 1000) 각 테스트 케이스는 한 줄로 이루어져 있으며, 0과 1로 이루어진 문자열이 주어진다. 문자열의 길이는 항상 짝수이고, 1000보다 작 www.acmicpc.net 문제 풀이 문자열의 가장 가운데에 위치한 두 문자만 비교해주어도 된다. 두 문자가 같을 경우 "Do-it" 을 출력하고, 틀릴 경우 "Do-it-Not"을 출력한다. 정답 코드 for _ in range(int(input())) : s = input() if s[len(s) // 2 - 1] == s[len(s) // 2] : print("Do-it") else : print("Do-it-Not")
문제 링크 5753번: Pascal Library Pascal University, one of the oldest in the country, needs to renovate its Library Building, because after all these centuries the building started to show the effects of supporting the weight of the enormous amount of books it houses. To help in the renov www.acmicpc.net 문제 풀이 모든 케이스마다 참석한 사람이 한명이라도 존재할 때 "yes"를 출력하고, 아니라면 "no"를 출력해준다. 정답 코드 while True : lst = [*map(..
문제 링크 5691번: 평균 중앙값 문제 세 정수 A, B, C의 평균은 (A+B+C)/3이다. 세 정수의 중앙값은 수의 크기가 증가하는 순서로 정렬했을 때, 가운데 있는 값이다. 두 정수 A와 B가 주어진다. 이때, A, B, C의 평균과 중앙값을 같게 만드는 www.acmicpc.net 문제 풀이 평균과 중앙값을 가장 작게 만드는 수 c를 찾는 방법은 간단하다. a, b, c 중 c가 가장 작은 수가 되면 된다. 따라서 c, a, b 순으로 수열이 만들어 질 것이다. 따라서 a와 b의 차이는 c와 a의 차와 같으므로 값을 쉽게 구할 수 있다. 정답 코드 while True : a, b = map(int, input().split()) if a == b == 0 : break print(2 * a - b)
문제 링크 5666번: Hot Dogs In 2012 a new world record was set in the famous Nathan’s Hot Dog Eating Competition: the champion, Joey Chestnut, ate 68 hot dogs in ten minutes, an amazing increase from the 62 hot dogs eaten by the same Chestnut in 2011. Nathan’s Famous Corporation, www.acmicpc.net 문제 풀이 입력값에 EOF가 들어올 때 까지 계속 계산 결과를 출력해준다. 계산은 단순 사칙연산이고, 소숫점 2번째 자리까지 출력한다. 정답 코드 try : while True : a, b =..
문제 링크 5356번: Triangles Read in a letter and a number. The number indicates how big the letter triangle should be. The number indicating the size of the triangle will have a range from 0 to 250 (i.e., num>=0 and num