Python

Algorithm/PS

[BOJ/백준] 6190 - Another Cow Number Game [python]

문제 링크 6190번: Another Cow Number Game The cows are playing a silly number game again. Bessie is tired of losing and wants you to help her cheat. In this game, a cow supplies a number N (1

Algorithm/PS

[BOJ/백준] 6162 - Superlatives [python]

문제 링크 6162번: Superlatives Typically, droughts are classified into “abnormally dry”, “moderate drought”, “severe drought”, “extreme drought”, and “exceptional drought”. The current drought is so “exceptional” in most of California that there have been discuss www.acmicpc.net 문제 풀이 두 입력값 A, E를 입력 받으면, 조건에 따라 출력해주는 문제이다. E보다 A가 5배 클때마다 "mega"를 더해서 출력해준다. 만약 25배가 클 경우, "mega mega"를 더해 출력해준다. 정답 코드 f..

Algorithm/PS

[BOJ/백준] 6131 - 완전 제곱수 [python]

문제 링크 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..

Algorithm/PS

[BOJ/백준] 6030 - Scavenger Hunt [python]

문제 링크 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

Algorithm/PS

[BOJ/백준] 5949 - Adding Commas [python]

문제 링크 5949번: Adding Commas Bessie is working with large numbers N (1

Algorithm/PS

[BOJ/백준] 5789 - 한다 안한다 [python]

문제 링크 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")

Algorithm/PS

[BOJ/백준] 5753 - Pascal Library [python]

문제 링크 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(..

Algorithm/PS

[BOJ/백준] 5691 - 평균 중앙값 문제 [python]

문제 링크 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)

chanwoong1
'Python' 태그의 글 목록 (11 Page)