Advertisement
Spocoman

Exam Schedule

Oct 12th, 2023 (edited)
1,032
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ExamSchedule
  4. {
  5.     public class Program
  6.     {
  7.         public static void Main()
  8.         {
  9.             int hours = int.Parse(Console.ReadLine());
  10.             int minutes = int.Parse(Console.ReadLine());
  11.             string dayPart = Console.ReadLine();
  12.             int hoursAdded = int.Parse(Console.ReadLine());
  13.             int minutesAdded = int.Parse(Console.ReadLine());
  14.  
  15.             int result = (hours + hoursAdded) * 60 + minutes + minutesAdded;
  16.             int totalHours = result / 60 % 24;
  17.             int totalMinutes = result % 60;
  18.  
  19.             dayPart = totalHours >= 12 ? (dayPart == "AM" ? "PM" : "AM") : dayPart;
  20.             totalHours -= totalHours > 12 ? 12 : 0;
  21.  
  22.             Console.WriteLine($"{totalHours:d2}:{totalMinutes:d2}:{dayPart}");
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement