백준 - 조건문
2022. 11. 12. 12:41ㆍ백준 - Python
728x90
백준의 조건문 문제들을 python으로 풀이한 것입니다.
1. 두 수 비교하기
문제 해결 코드는 다음과 같습니다.
a, b = map(int, input().split())
if a > b:
print('>')
elif a < b:
print('<')
else:
print('==')
2. 시험 성적
문제 해결 코드는 다음과 같습니다.
score = int(input())
if score >= 90:
print('A')
elif score >= 80:
print('B')
elif score >= 70:
print('C')
elif score >= 60:
print('D')
else:
print('F')
3. 윤년
문제 해결 코드는 다음과 같습니다.
year = int(input())
if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
print('1')
else:
print('0')
4. 사분면 고르기
문제 해결 코드는 다음과 같습니다.
x = int(input())
y = int(input())
if x > 0 and y > 0:
print('1')
elif x < 0 and y > 0:
print('2')
elif x < 0 and y < 0:
print('3')
else:
print('4')
5. 알람 시계
문제 해결 코드는 다음과 같습니다.
h, m = map(int, input().split())
m -= 45
if m < 0:
h -= 1
m = 60 + m
if h < 0:
h = 24 + h
print(h, m)
6. 오븐 시계
문제 해결 코드는 다음과 같습니다.
h, m = map(int, input().split())
t = int(input())
if t > 60:
h += (t // 60)
t -= 60 * (t // 60)
m += t
if m >= 60:
h += 1
m = m - 60
if h >= 24:
h = h - 24
print(h, m)
7. 주사위 세개
문제 해결 코드는 다음과 같습니다.
a, b, c = map(int, input().split())
if a == b and b == c:
pay = 10000 + a * 1000
print(pay)
elif a == b or b == c or a == c:
if a == b:
pay = 1000 + a * 100
print(pay)
elif a == c:
pay = 1000 + a * 100
print(pay)
else:
pay = 1000 + b * 100
print(pay)
else:
pay = max([a, b, c]) * 100
print(pay)
728x90
'백준 - Python' 카테고리의 다른 글
백준 - 2차원 배열 (0) | 2022.11.12 |
---|---|
백준 - 문자열 (1) | 2022.11.12 |
백준 - 1차원 배열 (0) | 2022.11.12 |
백준 - 반복문 (0) | 2022.11.12 |
백준 - 입출력과 사칙연산 (0) | 2022.11.12 |