MiroslavKisov

SoftUniKaraoke

Nov 27th, 2017
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02.SoftUniKaraoke
  6. {
  7.     public class StartUp
  8.     {
  9.         public static void Main()
  10.         {
  11.             List<Performer> performers = new List<Performer>();
  12.             List<string> participants = Console.ReadLine()
  13.                 .Split(',').ToList();
  14.             for (int i = 0; i < participants.Count; i++)
  15.             {
  16.                 participants[i] = participants[i].Trim();
  17.             }
  18.             List<string> songs = Console.ReadLine()
  19.                 .Split(',').ToList();
  20.             for (int i = 0; i < songs.Count; i++)
  21.             {
  22.                 songs[i] = songs[i].Trim();
  23.             }
  24.             while (true)
  25.             {
  26.                 string input = Console.ReadLine();
  27.                 if (input == "dawn")
  28.                 {
  29.                     break;
  30.                 }
  31.                 var awardsAndPerformers = input
  32.                     .Split(',')
  33.                     .ToList();
  34.                 string participant = awardsAndPerformers[0].Trim();
  35.                 string song = awardsAndPerformers[1].Trim();
  36.                 string award = awardsAndPerformers[2].Trim();
  37.                 if (participants.Contains(participant) && songs.Contains(song))
  38.                 {
  39.                     Performer performer = new Performer();
  40.                     performer.Name = participant;
  41.                     if (performers.Any(x => x.Name == participant))
  42.                     {
  43.                         var currentPerformer = performers.First(x => x.Name == participant);
  44.                         if (!currentPerformer.Awards.Contains(award))
  45.                         {
  46.                             currentPerformer.Awards.Add(award);
  47.                         }
  48.                     }
  49.                     else
  50.                     {
  51.                         performers.Add(performer);
  52.                         performer.Awards.Add(award);
  53.                     }
  54.                 }
  55.             }
  56.             PrintResult(performers);
  57.         }
  58.  
  59.         private static void PrintResult(List<Performer> performers)
  60.         {
  61.             if (performers.Count > 0)
  62.             {
  63.                 foreach (Performer performer in performers.OrderByDescending(x => x.Awards.Count).ThenBy(x => x.Name))
  64.                 {
  65.                     Console.WriteLine($"{performer.Name}: {performer.Awards.Count} awards");
  66.                     foreach (var award in performer.Awards.OrderBy(x => x))
  67.                     {
  68.                         Console.WriteLine($"--{award}");
  69.                     }
  70.                 }
  71.             }
  72.             else
  73.             {
  74.                 Console.WriteLine("No awards");
  75.             }
  76.         }
  77.     }
  78.     class Performer
  79.     {
  80.         public string Name { get; set; }
  81.         public List<string> Awards { get; set; }
  82.         public Performer()
  83.         {
  84.             Awards = new List<string>();
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment