bullit3189

Movie Time

Jun 10th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5.  
  6. namespace _04MovieTime
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. string genre = Console.ReadLine();
  13. string duration = Console.ReadLine();
  14.  
  15. Dictionary<string, string> movieTime = new Dictionary<string, string>();
  16.  
  17. TimeSpan totalTime = new TimeSpan();
  18.  
  19. while (true)
  20. {
  21. string command = Console.ReadLine();
  22.  
  23. if(command == "POPCORN!")
  24. {
  25. break;
  26. }
  27.  
  28. string[] tokens = command.Split("|");
  29. string name = tokens[0];
  30. string currGenre = tokens[1];
  31. int[] spliitedTime = tokens[2].Split(":").Select(int.Parse).ToArray();
  32. int hours = spliitedTime[0];
  33. int mins = spliitedTime[1];
  34. int secs = spliitedTime[2];
  35.  
  36. TimeSpan currTime = new TimeSpan(hours, mins, secs);
  37. totalTime += currTime;
  38.  
  39.  
  40. if(currGenre == genre)
  41. {
  42. movieTime.Add(name, tokens[2]);
  43. }
  44.  
  45.  
  46. }
  47.  
  48. if(duration == "Short")
  49. {
  50. foreach (var kvp in movieTime.OrderBy(x=>x.Value).ThenBy(x=>x.Key))
  51. {
  52. string wife = Console.ReadLine();
  53.  
  54. if(wife == "Yes")
  55. {
  56. Console.WriteLine(kvp.Key);
  57. Console.WriteLine($"We're watching {kvp.Key} - {kvp.Value}");
  58. break;
  59. }
  60. else
  61. {
  62. Console.WriteLine(kvp.Key);
  63. }
  64. }
  65. }
  66. else
  67. {
  68. foreach (var kvp in movieTime.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  69. {
  70. string wife = Console.ReadLine();
  71.  
  72. if (wife == "Yes")
  73. {
  74. Console.WriteLine(kvp.Key);
  75. Console.WriteLine($"We're watching {kvp.Key} - {kvp.Value}");
  76. break;
  77. }
  78. else
  79. {
  80. Console.WriteLine(kvp.Key);
  81. }
  82. }
  83. }
  84.  
  85. Console.WriteLine($"Total Playlist Duration: {totalTime}");
  86. }
  87. }
  88. }
Add Comment
Please, Sign In to add comment