diff --git a/code_study/Baekjoon/python/3029.py b/code_study/Baekjoon/python/3029.py new file mode 100644 index 0000000..e067dcf --- /dev/null +++ b/code_study/Baekjoon/python/3029.py @@ -0,0 +1,17 @@ +h1, m1, s1 = map(int, input().split(":")) +h2, m2, s2 = map(int, input().split(":")) + +if h1 == h2 and m1 == m2 and s1 == s2 : + print("24:00:00") +else : + t1 = h1*3600 + m1*60 + s1 + t2 = h2*3600 + m2*60 + s2 + + diff = t2 - t1 if t2 > t1 else t2 - t1 + 24 * 3600 + + h = diff // 3600 + m = (diff % 3600) // 60 + s = diff % 60 + + print(f"{h:02d}:{m:02d}:{s:02d}") + \ No newline at end of file diff --git a/code_study/Baekjoon/swift/17387.swift b/code_study/Baekjoon/swift/17387.swift new file mode 100644 index 0000000..51cf6d8 --- /dev/null +++ b/code_study/Baekjoon/swift/17387.swift @@ -0,0 +1,70 @@ +func crossProduct(_ X: [Int], _ Y: [Int], _ Z: [Int]) -> Int { + let XY = [Y[0] - X[0], Y[1] - X[1]] + let XZ = [Z[0] - X[0], Z[1] - X[1]] + + let val = XY[0]*XZ[1] - XY[1]*XZ[0] + + return val > 0 ? 1 : val < 0 ? -1 : 0 +} + +func pointSort(_ x1: Int, _ y1: Int, _ x2: Int, _ y2: Int)-> ([Int], [Int]) { + if x1 < x2 { + return ([x1, y1], [x2,y2]) + } + else if x1 > x2 { + return ([x2, y2], [x1,y1]) + } + else if y1 < y2 { + return ([x1, y1], [x2,y2]) + } + else { + return ([x2, y2], [x1,y1]) + } +} + +func pointCompare(_ X: [Int], _ Y: [Int]) -> Bool { + if X[0] < Y[0] { + return true + } + else if X[0] == Y[0] && X[1] <= Y[1] { + return true + } + else { + return false + } +} + +func main() -> Int { + guard let line1 = readLine(), + let line2 = readLine() + else { return -1 } + + let L1 = line1.split(separator: " ").compactMap{Int($0)} + let L2 = line2.split(separator: " ").compactMap{Int($0)} + + let x1 = L1[0], y1 = L1[1], x2 = L1[2], y2 = L1[3] + let x3 = L2[0], y3 = L2[1], x4 = L2[2], y4 = L2[3] + + let (A, B) = pointSort(x1, y1, x2, y2) + let (C, D) = pointSort(x3, y3, x4, y4) + + let ABCD = crossProduct(A, B, C) * crossProduct(A, B, D) + let CDAB = crossProduct(C, D, A) * crossProduct(C, D, B) + + if ABCD == 0 && CDAB == 0 { + if pointCompare(A, D) && pointCompare(C, B) { + return 1 + } + else { + return 0 + } + } + + if ABCD <= 0 && CDAB <= 0 { + return 1 + } + + return 0 +} + +print(main()) \ No newline at end of file