Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- // A beer time is after 1:00 PM and before 3:00 AM. Write a program that enters a time in format
- // “hh:mm tt” (an hour in range [01...12], a minute in range [00…59] and AM / PM designator) and
- // prints “beer time” or “non-beer time” according to the definition above or “invalid time” if
- // the time cannot be parsed. Note that you may need to learn how to parse dates and times.
- class Pr10BeerTime
- {
- static void Main(string[] args)
- {
- Console.Write("Enter how many tests you would like to run: ");
- int tests = int.Parse(Console.ReadLine());
- for (int test = 0; test < tests; test++)
- {
- string time = Console.ReadLine();
- int timeLenght = time.Length;
- string minutes = time.Substring(timeLenght - 5, 2);
- int minutesInt = int.Parse(minutes);
- string designator = time.Substring(timeLenght - 2, 2);
- string hours;
- if (timeLenght == 7)
- {
- hours = time.Substring(0, 1);
- }
- else
- {
- hours = time.Substring(0, 2);
- }
- int hoursInt = int.Parse(hours);
- int totalTime = hoursInt * 60 + minutesInt;
- if (totalTime >= 60 && designator.Equals("PM"))
- {
- Console.WriteLine("beer time");
- continue;
- }
- else if (totalTime < 180 && designator.Equals("AM"))
- {
- Console.WriteLine("beer time");
- continue;
- }
- else
- {
- Console.WriteLine("non-beer time");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement