You are viewing a single comment's thread. Return to all comments →
swift Solution
let returnedDate = readLine()!.components(separatedBy: .whitespaces) let dueDate = readLine()!.components(separatedBy: .whitespaces) let dueDateComponent: (day: String, month: String, year: String) = (dueDate[0], dueDate[1], dueDate[2]) let returnedComponent: (day: String, month: String, year: String) = (returnedDate[0], returnedDate[1], returnedDate[2]) let dueDateYear = Int(dueDateComponent.year) ?? Int.min let returnedYear = Int(returnedComponent.year) ?? Int.min let dueDateMonth = Int(dueDateComponent.month) ?? Int.min let returnedMonth = Int(returnedComponent.month) ?? Int.min let dueDateDay = Int(dueDateComponent.day) ?? Int.min let returnedDay = Int(returnedComponent.day) ?? Int.min func calculateFine() { guard returnedYear >= dueDateYear else { print(0) return } guard returnedYear == dueDateYear else { print(10000) return } guard returnedMonth <= dueDateMonth else { let diff = returnedMonth - dueDateMonth print(diff*500) return } guard returnedDay <= dueDateDay else { let diff = returnedDay - dueDateDay print(diff*15) return } print(0) } calculateFine()
Seems like cookies are disabled on this browser, please enable them to open this website
Day 26: Nested Logic
You are viewing a single comment's thread. Return to all comments →
swift Solution