사칙연산

Algorithm/PS

[BOJ/백준] 6975 - Deficient, Perfect, and Abundant [python]

문제 링크 6975번: Deficient, Perfect, and Abundant Write a program that repeatedly reads a positive integer, determines if the integer is deficient, perfect, or abundant, and outputs the number along with its classification. A positive integer, n, is said to be perfect if the sum of its proper diviso www.acmicpc.net 문제 풀이 주어진 입력값을 조건에 따라 출력해준다. 먼저, 입력값으로 자기 자신을 제외한 약수의 리스트를 구해준다. 약수 리스트의 합이 입력값보다 작으면..

Algorithm/PS

[BOJ/백준] 6974 - Long Division [python]

문제 링크 6974번: Long Division In days of yore (circa 1965), mechanical calculators performed division by shifting and repeated subtraction. For example, to divide 987654321 by 3456789, the numbers would first be aligned by their leftmost digit (see (1) below), and the divisor subtracte www.acmicpc.net 문제 풀이 이 문제는 몫과 나머지를 구해서 출력하는 문제이다. 파이썬에서는 큰 수 연산을 지원하기 때문에 아주 간단하게 문제를 풀 수 있다. 정답 코드 for _ in rang..

Algorithm/PS

[BOJ/백준] 6812 - Good times [python]

문제 링크 6812번: Good times A mobile cell service provider in Ottawa broadcasts an automated time standard to its mobile users that reflects the local time at the user’s actual location in Canada. This ensures that text messages have a valid local time attached to them. For example www.acmicpc.net 문제 풀이 이 문제는 주어진 입력값으로 각각의 지역 시간대로 변환해 출력해야하는 문제이다. 이 문제에서 주의할 점은 다음과 같다. 입력값은 0부터 2359사이의 수이다. (ex. 0을 ..

Algorithm/PS

[BOJ/백준] 6780 - Sumac Sequences [python]

문제 링크 6780번: Sumac Sequences In a sumac sequence, t1, t2, .., tm, each term is an integer greater than or equal 0. Also, each term, starting with the third, is the difference of the preceding two terms (that is, tn+2 = tn − tn+1 for n ≥ 1). The sequence terminates at tm if tm−1 www.acmicpc.net 문제 풀이 입력값으로 주어진 값이 t1, t2일 때, t3은 t2 - t1이고, t3 < t2의 관계여야 한다. 이 규칙을 지키는 수열의 길이를 구하면 된다. 정답 코드 cnt = 2 ..

Algorithm/PS

[BOJ/백준] 6779 - Who Has Seen The Wind [python]

문제 링크 6779번: Who Has Seen The Wind The input is two non-negative integers: h, the humidity factor, followed by M, the maximum number of hours Margaret will wait for the weather balloon to return to ground. You can assume 0 ≤ h ≤ 100 and 0 < M < 240. www.acmicpc.net 문제 풀이 문제에 주어진 방정식을 가지고 계산된 A가 0 이하가 되는 경우의 최소 t값을 구하는 문제이다. 만약 M보다 t가 커진다면 "The balloon does not touch ground in the given time."이라는..

Algorithm/PS

[BOJ/백준] 6721 - Backward numbers [python]

문제 링크 6721번: Backward numbers Backward numbers are numbers written in ordinary Arabic numerals but the order of the digits is reversed. The first digit becomes the last, and vice versa. For example, the number 1245 becomes 5421. Note that all leading zeroes are omitted. This means that www.acmicpc.net 문제 풀이 주어진 두 입력값을 거꾸로 뒤집어서 합을 구해준 뒤, 그 합을 다시 뒤집어서 출력해주면 된다. 정답 코드 for _ in range(int(input())) :..

Algorithm/PS

[BOJ/백준] 6322 - 직각 삼각형의 두 변 [python]

문제 링크 6322번: 직각 삼각형의 두 변 입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 한 줄로 이루어져 있고, 직각 삼각형의 세 변의 길이 a, b, c가 주어진다. a, b, c중 하나는 -1이며, -1은 알 수 없는 변의 길이 www.acmicpc.net 문제 풀이 이 문제의 입력값은 a, b, c의 형식으로 들어오고, 한 변이 -1일 경우, 직각삼각형이 되는 수를 찾는 문제이다. 문제에서는 c가 항상 가장 긴 변으로 나온다. 따라서 a, b를 찾는 경우는 c^2 - b^2 = a^2 혹은 c^2 - a^2 = b^2의 형식이고, c를 찾는 방법은 a^2 + b^2 = c^2를 통해 찾아준다. 문제에서 불가능한 경우도 존재하는데, c가 가장 긴 변이 아닐 경우이다. c^2..

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