baekjoon 20260306
This commit is contained in:
parent
dc49e2c906
commit
7eeac4c949
37
code_study/Baekjoon/swift/10775.swift
Normal file
37
code_study/Baekjoon/swift/10775.swift
Normal 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())
|
||||||
7
code_study/Baekjoon/swift/2754.swift
Normal file
7
code_study/Baekjoon/swift/2754.swift
Normal 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))
|
||||||
Loading…
x
Reference in New Issue
Block a user