diff --git a/code_study/Baekjoon/python/17404.py b/code_study/Baekjoon/python/17404.py new file mode 100644 index 0000000..2ae0d30 --- /dev/null +++ b/code_study/Baekjoon/python/17404.py @@ -0,0 +1,37 @@ +import sys + +input = sys.stdin.readline + +maxCost = 1000 +N = int(input()) +R = [] +G = [] +B = [] + +for _ in range(N) : + r, g, b = map(int, input().split()) + R.append(r) + G.append(g) + B.append(b) + +result = [] + +for i in range(3) : + dpR = [maxCost if i != 0 else R[0]] + dpG = [maxCost if i != 1 else G[0]] + dpB = [maxCost if i != 2 else B[0]] + + for n in range(1, N) : + r, g, b = R[n], G[n], B[n] + dpR.append(r + min(dpG[n-1], dpB[n-1])) + dpG.append(g + min(dpR[n-1], dpB[n-1])) + dpB.append(b + min(dpR[n-1], dpG[n-1])) + + if i==0 : + result.append(min(dpG[N-1], dpB[N-1])) + elif i==1 : + result.append(min(dpR[N-1], dpB[N-1])) + else : + result.append(min(dpR[N-1], dpG[N-1])) + +print(min(result)) \ No newline at end of file diff --git a/code_study/Baekjoon/swift/1918.swift b/code_study/Baekjoon/swift/1918.swift new file mode 100644 index 0000000..88356e5 --- /dev/null +++ b/code_study/Baekjoon/swift/1918.swift @@ -0,0 +1,51 @@ +func opPriority(_ op: Character) -> Int { + return (op == "*") || (op == "/") ? 2 : (op == "+") || (op == "-") ? 1 : 0 +} + +func compareToPriority(_ op1: Character, _ op2: Character) -> Bool { + return opPriority(op1) >= opPriority(op2) +} + +if let input = readLine() { + var result: String = "" + var op: [Character] = [] + + for c in input { + if "A" <= c && c <= "Z" { + result.append(c) + } + else { + if c == "(" { + op.append(c) + } + else if c == ")" { + while !op.isEmpty && op.last != "(" { + if let top = op.popLast() { + result.append(top) + } + } + + if !op.isEmpty { + _ = op.popLast() + } + } + else { + while !op.isEmpty && compareToPriority(op.last!, c) { + if let top = op.popLast() { + result.append(top) + } + } + + op.append(c) + } + } + } + + while !op.isEmpty { + if let top = op.popLast() { + result.append(top) + } + } + + print(result) +}