From f530361b18116966ee10f01b6e3a9b7187dfa764 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Wed, 8 Apr 2026 14:40:09 +0900 Subject: [PATCH] baekjoon 20260408 --- code_study/Baekjoon/python/4504.py | 5 ++ code_study/Baekjoon/swift/20303.swift | 91 +++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 code_study/Baekjoon/python/4504.py create mode 100644 code_study/Baekjoon/swift/20303.swift diff --git a/code_study/Baekjoon/python/4504.py b/code_study/Baekjoon/python/4504.py new file mode 100644 index 0000000..3751184 --- /dev/null +++ b/code_study/Baekjoon/python/4504.py @@ -0,0 +1,5 @@ +res = [] +n = int(input()) +while (m := int(input())) != 0 : + res.append(f"{m} is NOT a multiple of {n}." if m%n else f"{m} is a multiple of {n}.") +print("\n".join(res)) \ No newline at end of file diff --git a/code_study/Baekjoon/swift/20303.swift b/code_study/Baekjoon/swift/20303.swift new file mode 100644 index 0000000..b76b2de --- /dev/null +++ b/code_study/Baekjoon/swift/20303.swift @@ -0,0 +1,91 @@ +import Foundation + +final class FileIO { + private let buffer:[UInt8] + private var index: Int = 0 + + init(fileHandle: FileHandle = FileHandle.standardInput) { + + buffer = Array(try! fileHandle.readToEnd()!) + [UInt8(0)] // 인덱스 범위 초과 방지 + } + + @inline(__always) private func read() -> UInt8 { + defer { index += 1 } + return buffer[index] + } + + @inline(__always) func readInt() -> Int { + var sum = 0 + var now = read() + var isPositive = true + + while now == 10 || now == 32 { now = read() } // 공백과 줄바꿈 무시 + if now == 45 { isPositive = false; now = read() } // 음수 처리 + + while now >= 48, now <= 57 { + sum = sum * 10 + Int(now-48) + now = read() + } + + return sum * (isPositive ? 1 : -1) + } +} + +func main() { + let fp = FileIO() + + let N = fp.readInt(), M = fp.readInt(), K = fp.readInt() + var candy: [Int] = [0] + for _ in 1...N { + candy.append(fp.readInt()) + } + + var roots: [Int] = (0...N).map{Int($0)} + var rank: [Int] = Array(repeating: 0, count: N+1) + + func find(_ x: Int) -> Int { + if x != roots[x] { roots[x] = find(roots[x]) } + return roots[x] + } + + func union(_ x: Int, _ y: Int) { + var a = find(x), b = find(y) + + if a == b { return } + + if rank[a] < rank[b] { swap(&a, &b) } + + roots[b] = a + + if rank[a] == rank[b] { rank[a] += 1 } + } + + for _ in 0..