baekjoon 20260306

This commit is contained in:
songyc macbook 2026-03-06 22:04:28 +09:00
parent dc49e2c906
commit 7eeac4c949
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,37 @@
func solve() -> Int {
guard let G: Int = Int(readLine() ?? ""),
let P: Int = Int(readLine() ?? "")
else { return 0 }
var root: [Int] = Array(0...G)
func find(_ x: Int) -> Int {
if x != root[x] {
root[x] = find(root[x])
}
return root[x]
}
func union(_ x: Int, _ y: Int) {
root[find(y)] = find(x)
}
var ans: Int = 0
for _ in 0..<P {
guard let g: Int = Int(readLine() ?? "") else { break }
let target = find(g)
if target == 0 {
break
}
ans += 1
union(target - 1, target)
}
return ans
}
print(solve())

View File

@ -0,0 +1,7 @@
let s = readLine()!
let (g, p) = (s.first!, s.last!)
let grade: [Character: Float] = ["A" : 4.0, "B" : 3.0, "C" : 2.0, "D" : 1.0, "F" : 0.0]
let point: [Character: Float] = ["+" : 0.3, "0" : 0.0, "-" : -0.3]
print(grade[g]! + (point[p] ?? 0.0))