tochka

Movie Time

Apr 29th, 2018
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5.  
  6. namespace Movie_Time1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string favouriteGenre = Console.ReadLine();
  13.             string movieDuration = Console.ReadLine();
  14.  
  15.             Dictionary<string, Dictionary<string, TimeSpan>> dict = new Dictionary<string, Dictionary<string, TimeSpan>>();
  16.  
  17.             string info = Console.ReadLine();
  18.  
  19.             while (info != "POPCORN!")
  20.             {
  21.                 string[] tokens = info.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
  22.  
  23.                 string movieName = tokens[0];
  24.                 string genre = tokens[1];
  25.                 TimeSpan time = TimeSpan.ParseExact(tokens[2], "hh\\:mm\\:ss", CultureInfo.InvariantCulture);
  26.  
  27.                 if(!dict.ContainsKey(genre))
  28.                 {
  29.                     dict.Add(genre, new Dictionary<string, TimeSpan>());
  30.                 }
  31.  
  32.                 if(!dict[genre].ContainsKey(movieName))
  33.                 {
  34.                     dict[genre].Add(movieName, time);
  35.                 }
  36.  
  37.                 info = Console.ReadLine();
  38.             }
  39.  
  40.             string command = Console.ReadLine();
  41.  
  42.             int countWhileYes = 1;
  43.  
  44.             while (command != "Yes")
  45.             {
  46.  
  47.                 countWhileYes++;
  48.  
  49.                 command = Console.ReadLine();
  50.             }
  51.  
  52.             List<string> movies = new List<string>();
  53.  
  54.             if (movieDuration == "Short")
  55.             {
  56.                 foreach (var movie in dict[favouriteGenre].OrderBy(a => a.Value).ThenBy(a => a.Key).Take(countWhileYes))
  57.                 {
  58.                     Console.WriteLine(movie.Key);
  59.                     movies.Add($"{movie.Key} - {movie.Value}");
  60.                 }
  61.             }
  62.  
  63.             if(movieDuration == "Long")
  64.             {
  65.                 foreach (var movie in dict[favouriteGenre].OrderByDescending(a => a.Value).ThenBy(a => a.Key).Take(countWhileYes))
  66.                 {
  67.                     Console.WriteLine(movie.Key);
  68.                     movies.Add($"{movie.Key} - {movie.Value}");
  69.                 }
  70.             }
  71.  
  72.             List<TimeSpan> list = new List<TimeSpan>();
  73.             foreach (var item in dict)
  74.             {
  75.                 foreach (var itemm in item.Value)
  76.                 {
  77.                     list.Add(itemm.Value);
  78.                 }
  79.             }
  80.  
  81.             TimeSpan total = new TimeSpan();
  82.             foreach (var item in list)
  83.             {
  84.                 total = new TimeSpan(list.Sum(t => t.Ticks));
  85.             }
  86.  
  87.             Console.WriteLine($"We're watching {movies.Last()}");
  88.             Console.WriteLine($"Total Playlist Duration: {total}");
  89.  
  90.         }
  91.     }
  92. }
Add Comment
Please, Sign In to add comment