Advertisement
Spocoman

08. On Time for the Exam

Sep 18th, 2024
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.08 KB | None | 0 0
  1. package main
  2. import (
  3.     "fmt"
  4.     "math"
  5. )
  6.  
  7. func main() {
  8.     var hourExam, minuteExam, hourStudent, minuteStudent int
  9.     fmt.Scanln(&hourExam)
  10.     fmt.Scanln(&minuteExam)
  11.     fmt.Scanln(&hourStudent)
  12.     fmt.Scanln(&minuteStudent)
  13.    
  14.     var examMinutes = hourExam * 60 + minuteExam
  15.     var studentMinutes = hourStudent * 60 + minuteStudent
  16.     var time = int(math.Abs(float64(studentMinutes) - float64(examMinutes)))
  17.  
  18.     if (studentMinutes > examMinutes) {
  19.         fmt.Println("Late")
  20.         if (time < 60) {
  21.             fmt.Printf("%d minutes after the start", time)
  22.         } else {
  23.             fmt.Printf("%d:%02d hours after the start", time / 60, time % 60)
  24.         }
  25.     } else {
  26.         if (time <= 30) {
  27.             fmt.Println("On time")
  28.         } else {
  29.             fmt.Println("Early")
  30.         }
  31.         if (time != 0) {
  32.             if (time < 60) {
  33.                 fmt.Printf("%d minutes before the start", time)
  34.             } else {
  35.                 fmt.Printf("%d:%02d hours before the start", time / 60, time % 60)
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement