백준/백준 파이썬

백준 파이썬 Today I Learn 2023.06.26

군청레프 2023. 6. 30. 13:30
728x90

6/ 26 파이썬 공부
1. 백준 18698 The Walking Adam
Adam has just started learning how to walk (with some help from his brother Omar), and he falls down a lot. In order to balance himself, he raises his hands up in the air (that’s a true story), and once he puts his hands down, he falls.

You are given a string, each character represents a step he walks, if that character is ‘U’ that means his hands are up in this step, if this character is ‘D’ that means his hands are down and he fell down in this step. Your task is to count how many steps he will walk before falling down for the first time.

Your program will be tested on one or more test cases. The first line of the input will be a single integer T (1 ≤ T ≤ 100) representing the number of test cases. Followed by T test cases.

Each test case will consist of a single line, containing a non-empty string of at most 100 characters, and each character is either ‘U’ or ‘D’. The characters from left to right represent Adam’s steps in the order he walks them.

For each test case print a single line containing the number of steps that Adam will walk before falling down, or the length of the string if he won’t fall down.

>>>해석
이제 막 걸음마를 떼기 시작한 아담은, 자주 넘어지고 있습니다. 
아직 아담은 손을 번쩍 들어 올린 상태여야만 걸을 수 있고, 손을 내리게 되면 균형을 잃고 넘어지고 맙니다.
아담의 행동을 나타내는 'U' 와 'D'로만 구성된 문자열이 주어집니다. 
각각 'U'는 아담이 손을 들어 올린 상태임을, 'D'는 아담이 손을 내린 상태임을 의미합니다.
아담의 걸음마 연습을 도와주기 위해, 아담이 처음으로 넘어지기 전까지 몇 걸음을 걸었는지 계산해주는 프로그램을 작성해봅시다.

입력의 첫 줄에는 테스트 케이스의 개수를 뜻하는 정수 T (1 ≤ T ≤ 100)가 주어집니다.

각 테스트 케이스에는 아담의 행동을 시간순으로 나타낸 최대 100자 이내의 문자열 한 줄이 입력됩니다. 
해당 문자열은 공백이 존재하지 않고 'U'와 'D'로만 구성되어 있습니다.

각 테스트 케이스에 대해 아담이 처음으로 넘어질 때까지의 걸음 수를 출력합니다.

>>>코드

for _ in range(int(input())):
    s = input()
    result = 0
    for i in s:
        if i == 'D':
            break
        result += 1
    print(result)



2. 백준 21633 Bank Transfer
Tanya has an account in "Redgotts" bank. The bank has the commission to transfer money to "Bluegotts" bank that her friend Vanya has the account in.
Tanya has read her bank rules and learned the following:
The commission for the bank transfer is 25 tugriks plus 1% of the sum transferred. However, the commission is never smaller than 100 tugriks, and cannot exceed 2000 tugriks.
Tanya is planning to transfer k tugriks to Vanya. 
Help her find out what the commission would be.

Input is a single integer k (200 <= k <= 10^9).
Output one floating point value: the commission for the transfer. 
The value must be printed with at least two exact digits after the decimal point.

>>>해석
타냐는 레드고츠 은행에 계좌가 있습니다. 
그녀의 친구 바냐가 계좌를 가지고 있는 블루고츠 은행에 돈을 이체하려면 수수료를 내야 합니다.
타냐는 은행 약관을 보고 아래의 내용을 알게 됐습니다:
계좌 이체에 드는 수수료는 25 투그릭에 이체한 가격의 1%를 더한 값입니다. 
수수료는 최소 100 투그릭이며, 2000 투그릭을 넘지 않습니다.
타냐는 k 투그릭을 바냐에게 이체할 생각입니다. 그녀가 수수료가 얼마일지 계산하는 것을 도와줍시다.

입력은 한 개의 정수 k입니다. (200 <= k <= 10 ^ 9)
계좌 이체 수수료를 나타내는 하나의 부동 소수점 값을 출력합니다. 
출력한 값은 최소한 소수점 둘째 자리까지 정확히 일치해야 합니다.

>>>코드

k = float(input())
n = 25 + k*0.01
if n<100:
    print('100.00')
elif n>2000:
    print('2000.00')
else:
    print('%.2f' %(n))



3. 백준 21612 Boiling Water
At sea level, atmospheric pressure is 100 kPa and water begins to boil at 100◦C. As you go above sea level, atmospheric pressure decreases, and water boils at lower temperatures. As you go below sea level, atmospheric pressure increases, and water boils at higher temperatures. A formula relating atmospheric pressure to the temperature at which water begins to boil is

P = 5 × B − 400

where P is atmospheric pressure measured in kPa, and B is the temperature at which water begins to boil measured in ◦C.

Given the temperature at which water begins to boil, determine atmospheric pressure. Also determine if you are below sea level, at sea level, or above sea level.

Note that the science of this problem is generally correct but the values of 100◦C and 100 kPa are approximate and the formula is a simplification of the exact relationship between water’s boiling point and atmospheric pressure.

The input is one line containing an integer B where B ≥ 80 and B ≤ 200. This represents the temperature in ◦C at which water begins to boil.

The output is two lines. The first line must contain an integer which is atmospheric pressure measured in kPa. The second line must contain the integer -1, 0, or 1. This integer represents whether you are below sea level, at sea level, or above sea level, respectively.

>>>해석
해수면에서 기압은 100kPa이고 물은 섭씨 100도에서 끓기 시작합니다. 
해수면보다 높이 올라가면 기압이 내려가고, 물은 보다 낮은 온도에서 끓습니다. 
해수면 아래로 내려가면 기압은 올라가고, 물은 보다 높은 온도에서 끓습니다. 
기압과 물이 끓기 시작하는 온도의 관계를 서술하는 공식은 아래와 같습니다.

P = 5 * B - 400

P는 kPa 단위로 표현한 기압을, B는 섭씨 단위로 표현한 물이 끓기 시작하는 온도를 나타냅니다.
물이 끓기 시작하는 온도가 주어졌을 때, 기압을 구합시다. 
또한 현재 해수면 아래에 있는지, 해수면에 있는지, 혹은 해수면 위에 있는지도 판정합시다.
참고로 이 문제가 서술하는 과학은 대체적으로 맞지만, 섭씨 100도와 100kPa은 추정일 뿐이며 공식 역시 물이 끓기 시작하는 온도와 기압의 정확한 관계를 단순화한 것임을 알아둡시다.

한 줄에 B >= 80이고 B <= 200인 정수 B가 주어집니다. 
이것은 물이 끓기 시작하는 온도를 섭씨 단위로 표현한 값입니다.

출력은 두 줄입니다.
첫 줄은 kPa 단위로 표현한 기압을 나타내는 정수를 출력합니다. 둘째 줄은 -1, 0, 또는 1을 출력합니다. 
이는 각각 현재 해수면 아래에 있는지, 해수면에 있는지, 해수면 위에 있는지 나타내는 값입니다.

>>>코드

B = int(input())
P = 5 * B - 400
print(P)
if P > 100:
    print(-1)
elif P < 100:
    print(1)
else:
    print(0)
728x90