Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- namespace Movie_Time1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string favouriteGenre = Console.ReadLine();
- string movieDuration = Console.ReadLine();
- Dictionary<string, Dictionary<string, TimeSpan>> dict = new Dictionary<string, Dictionary<string, TimeSpan>>();
- string info = Console.ReadLine();
- while (info != "POPCORN!")
- {
- string[] tokens = info.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
- string movieName = tokens[0];
- string genre = tokens[1];
- TimeSpan time = TimeSpan.ParseExact(tokens[2], "hh\\:mm\\:ss", CultureInfo.InvariantCulture);
- if(!dict.ContainsKey(genre))
- {
- dict.Add(genre, new Dictionary<string, TimeSpan>());
- }
- if(!dict[genre].ContainsKey(movieName))
- {
- dict[genre].Add(movieName, time);
- }
- info = Console.ReadLine();
- }
- string command = Console.ReadLine();
- int countWhileYes = 1;
- while (command != "Yes")
- {
- countWhileYes++;
- command = Console.ReadLine();
- }
- List<string> movies = new List<string>();
- if (movieDuration == "Short")
- {
- foreach (var movie in dict[favouriteGenre].OrderBy(a => a.Value).ThenBy(a => a.Key).Take(countWhileYes))
- {
- Console.WriteLine(movie.Key);
- movies.Add($"{movie.Key} - {movie.Value}");
- }
- }
- if(movieDuration == "Long")
- {
- foreach (var movie in dict[favouriteGenre].OrderByDescending(a => a.Value).ThenBy(a => a.Key).Take(countWhileYes))
- {
- Console.WriteLine(movie.Key);
- movies.Add($"{movie.Key} - {movie.Value}");
- }
- }
- List<TimeSpan> list = new List<TimeSpan>();
- foreach (var item in dict)
- {
- foreach (var itemm in item.Value)
- {
- list.Add(itemm.Value);
- }
- }
- TimeSpan total = new TimeSpan();
- foreach (var item in list)
- {
- total = new TimeSpan(list.Sum(t => t.Ticks));
- }
- Console.WriteLine($"We're watching {movies.Last()}");
- Console.WriteLine($"Total Playlist Duration: {total}");
- }
- }
- }
Add Comment
Please, Sign In to add comment