[백준] 20546. 기적의 매매법 (Python)

yuuforest·2023년 7월 6일

구현

목록 보기
1/9
post-thumbnail

백준 문제 풀이 - 구현

📰 문제


문제 확인 🏃


💡 입출력 예제


100
10 20 23 34 55 30 22 19 12 45 23 44 34 38

>> BNP

준현이는 1월 1일에 10주를 매수한다. 따라서 1월 14일 380원의 자산을 가지게 된다.
성민이는 1월 8일에 5주를 매수한다. 따라서 1월 14일 195원의 자산을 가지게 된다.

100
10 20 23 34 55 30 22 19 12 45 23 44 34 38

>> TIMING

준현이는 1월 5일에 1주를 매수한다. 따라서 14일의 자산은 14원이다.
성민이는 1월 7일 3주를, 1월 8일 3주를 매수한다. 그리고 1월 13일에 전량 매도한다. 따라서 14일 자산은 36원이다.


💬 풀이


🎵 첫번째 풀이

# 준현이 VS 성민이

Money = int(input())                                # 초기 현금
MachineDuck = list(map(int, input().split()))       # 1일부터 14일까지의 주가

# 준현이
money_bnp = Money   
count_bnp = 0

# 성민이
money_timing = Money
count_timing = 0

for num, price in enumerate(MachineDuck):

    # 준현
    count_bnp += (money_bnp // price)
    money_bnp %= price

    # 성민
    temp = MachineDuck[num:num+4]

    if len(temp) < 4:
        continue

    if temp[0] < temp[1] < temp[2] < temp[3] and count_timing > 0:         # 매도
        money_timing += (count_timing * temp[3])
        count_timing = 0
    elif temp[0] > temp[1] > temp[2] > temp[3]:                             # 매수
        count_timing += (money_timing // temp[3])
        money_timing %= temp[3]

answer_bnp = money_bnp + count_bnp * MachineDuck[-1]
answer_timing = money_timing + count_timing * MachineDuck[-1] 

if answer_bnp < answer_timing:
    print("TIMING")
elif answer_bnp > answer_timing:
    print("BNP")
else:
    print("SAMESAME")


✒️ 생각


문제 이해가 어려워..

profile
🐥 Backend Developer 🐥

0개의 댓글