
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV189xUaI8UCFAZN
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
SSAFY 알고리즘 스터디 1번째, 알고리즘 리뷰
# 첫 번째 풀이, if문
T = int(input())
for test_case in range(1, T + 1):
p, q, r, s, w = map(int, input().split())
result = [p*w, 0, 0]
if w > r: # 요금이 임계값을 넘었다면
result[1] = q + s*(w-r)
else: # 넘지 않았다면
result[1] = q
if result[0] < result[1]: # a요금이 더 저렴하다면
result[2] = result[0]
else:
result[2] = result[1]
print("#"+str(test_case), result[2])
# 두 번째 풀이, lambda
T = int(input())
for test_case in range(1, T + 1):
p, q, r, s, w = map(int, input().split())
result = [p*w, 0, 0]
result[1] = q + s * (w - r) if w > r else q
result[2] = (lambda a, b: a if a < b else b)(result[0], result[1])
print("#"+str(test_case), result[2])
# 입력, 출력 예시
입력2
9 100 20 3 10
8 300 100 10 250
출력
#1 90
#2 1800
#2 1800
'Programming > Algorithm(Python)' 카테고리의 다른 글
[DFS] leetcode 841번 Keys and Rooms, class이해 (2) | 2023.10.18 |
---|---|
[구현] SWEA 10570 제곱 팰린드롬 수 (2) | 2023.10.16 |
[백준/python][구현] 10812번 - 바구니 순서 바꾸기 (0) | 2023.10.12 |
[백준/python][stack] 24463번 - 미로 (0) | 2023.10.12 |
[백준/python][브루트포스] 1018번 - 체스판 다시 칠하기 (0) | 2023.09.02 |

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV189xUaI8UCFAZN
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
SSAFY 알고리즘 스터디 1번째, 알고리즘 리뷰
# 첫 번째 풀이, if문
T = int(input())
for test_case in range(1, T + 1):
p, q, r, s, w = map(int, input().split())
result = [p*w, 0, 0]
if w > r: # 요금이 임계값을 넘었다면
result[1] = q + s*(w-r)
else: # 넘지 않았다면
result[1] = q
if result[0] < result[1]: # a요금이 더 저렴하다면
result[2] = result[0]
else:
result[2] = result[1]
print("#"+str(test_case), result[2])
# 두 번째 풀이, lambda
T = int(input())
for test_case in range(1, T + 1):
p, q, r, s, w = map(int, input().split())
result = [p*w, 0, 0]
result[1] = q + s * (w - r) if w > r else q
result[2] = (lambda a, b: a if a < b else b)(result[0], result[1])
print("#"+str(test_case), result[2])
# 입력, 출력 예시
입력2
9 100 20 3 10
8 300 100 10 250
출력
#1 90
#2 1800
#2 1800
'Programming > Algorithm(Python)' 카테고리의 다른 글
[DFS] leetcode 841번 Keys and Rooms, class이해 (2) | 2023.10.18 |
---|---|
[구현] SWEA 10570 제곱 팰린드롬 수 (2) | 2023.10.16 |
[백준/python][구현] 10812번 - 바구니 순서 바꾸기 (0) | 2023.10.12 |
[백준/python][stack] 24463번 - 미로 (0) | 2023.10.12 |
[백준/python][브루트포스] 1018번 - 체스판 다시 칠하기 (0) | 2023.09.02 |