Advertisement
Guest User

SoftuniKaraoke

a guest
Oct 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.48 KB | None | 0 0
  1. namespace _04_Sets_and_Dicts_Exer
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     public class Startup
  8.     {
  9.         public static void Main()
  10.         {
  11.             List<string> namesOfSingers = Console.ReadLine()
  12.                .Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries)
  13.                .ToList();
  14.  
  15.             List<string> songs = Console.ReadLine()
  16.                 .Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries)
  17.                 .ToList();
  18.  
  19.             List<Singer> allBullshits = new List<Singer>();
  20.  
  21.             string songSinging = Console.ReadLine();
  22.  
  23.             while (songSinging != "dawn")
  24.             {
  25.                 string[] songList = songSinging.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
  26.  
  27.                 string nameOutput = songList[0];
  28.                 string song = songList[1];
  29.                 string award = songList[2];
  30.  
  31.                 if (namesOfSingers.Any(a => a == nameOutput) && songs.Any(a => a == song))
  32.                 {
  33.  
  34.                     if (!allBullshits.Any(a => a.Name == nameOutput))
  35.                     {
  36.                         var singer = new Singer(nameOutput);
  37.                         allBullshits.Add(singer);
  38.                     }
  39.                     Singer currentSinger = allBullshits.First(e => e.Name == nameOutput);
  40.  
  41.                     if (!currentSinger.Awards.Any(e => e == award))
  42.                     {
  43.                         currentSinger.Awards.Add(award);
  44.                     }
  45.                 }
  46.  
  47.                 songSinging = Console.ReadLine();
  48.             }
  49.  
  50.             if (!allBullshits.Any())
  51.             {
  52.                 Console.WriteLine("No awards");
  53.                 return;
  54.             }
  55.  
  56.             foreach (var singer in allBullshits.OrderByDescending(e => e.Awards.Count).ThenBy(e => e.Name))
  57.             {
  58.                 Console.WriteLine($"{singer.Name}: {singer.Awards.Count} awards");
  59.  
  60.                 foreach (var award in singer.Awards.OrderBy(e => e))
  61.                 {
  62.                     Console.WriteLine($"--{award}");
  63.                 }
  64.             }
  65.         }
  66.  
  67.         class Singer
  68.         {
  69.             public string Name { get; set; }
  70.  
  71.             public List<string> Awards { get; set; }
  72.  
  73.             public Singer(string name)
  74.             {
  75.                 this.Name = name;
  76.                 this.Awards = new List<string>();
  77.             }
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement