Advertisement
Spocoman

04. Back In 30 Minutes

Jan 10th, 2022
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2.  
  3. namespace BackIn30Minutes
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int hour = int.Parse(Console.ReadLine());
  10.             int minute = int.Parse(Console.ReadLine());
  11.             int total = hour * 60 + minute + 30;
  12.             int hourTotal = total / 60;
  13.             int minuteTotal = total % 60;
  14.             if (hourTotal > 23)
  15.             {
  16.                 hourTotal %= 24;
  17.             }
  18.             if (minuteTotal > 9)
  19.             {
  20.                 Console.WriteLine($"{hourTotal}:{minuteTotal}");
  21.             }
  22.             else
  23.             {
  24.                 Console.WriteLine($"{hourTotal}:0{minuteTotal}");
  25.             }
  26.         }
  27.     }
  28. }
  29.  
  30.  
  31. With ternary operator and ...:D2 means a decimal with two digits( 7 - 07):
  32.  
  33.  
  34. using System;
  35.  
  36. namespace BackIn30Minutes
  37. {
  38.     class Program
  39.     {
  40.         static void Main(string[] args)
  41.         {
  42.             int total = int.Parse(Console.ReadLine()) * 60 + int.Parse(Console.ReadLine()) + 30;
  43.            
  44.             Console.WriteLine($"{(total / 60 > 23? default : total / 60)}:{total % 60:D2}");
  45.         }
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement