본문 바로가기
python-algorithm

백준 20546 🐜 기적의 매매법 🐜

by 무적김두칠 2022. 11. 12.

https://www.acmicpc.net/problem/20546

 

20546번: 🐜 기적의 매매법 🐜

1월 14일 기준 준현이의 자산이 더 크다면 "BNP"를, 성민이의 자산이 더 크다면 "TIMING"을 출력한다. 둘의 자산이 같다면 "SAMESAME"을 출력한다. 모든 결과 따옴표를 제외하고 출력한다.

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def bnp(cash, stocks):
    current_stocks=0
    for current_price in stocks:
        current_stocks += cash//current_price
        cash-= (cash//current_price)*current_price
    total = cash + current_stocks * stocks[-1]
    return total
 
def timing(cash, stocks):
    cnt_plus_days=0
    cnt_minus_days = 0
    current_stocks=0
    for i in range(1,len(stocks)):
        if stocks[i-1]<stocks[i]:
            cnt_plus_days+=1
            cnt_minus_days = 0
        elif stocks[i-1]>stocks[i]:
            cnt_minus_days+=1
            cnt_plus_days = 0
        if cnt_minus_days>=3:
            current_stocks += cash // stocks[i]
            cash -= (cash // stocks[i]) * stocks[i]
        elif cnt_plus_days>=3:
            cash += (current_stocks) * stocks[i]
            current_stocks = 0
 
    total = cash+ current_stocks * stocks[-1]
    return total
 
if __name__ == '__main__':
    cash = int(input())
    stocks = list(map(int, input().split()))
    if bnp(cash,stocks)>timing(cash, stocks):
        print("BNP")
    elif bnp(cash, stocks) < timing(cash, stocks):
        print("TIMING")
    else:
        print("SAMESAME")
 
cs

흠.. 어렵지 않죠 단순 구현 문제입니다.
조건을 잘 읽고 따라하시면 됩니다
Just implement in the condition

여담이지만 저는 아래처럼 33매매법을 하는데용..
제 계좌입니다
This not about programming, In real I trade like'timing' way
Here is my real account.. sh1t...

반응형

댓글