Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace _02.SoftUniKaraoke
  9. {
  10.     class Singer
  11.     {
  12.         public string Name { get; set; }
  13.         public List<string> Songs { get; set; }
  14.         public List<string> Awards { get; set; }
  15.  
  16.         public Singer()
  17.         {
  18.             Songs = new List<string>();
  19.             Awards = new List<string>();
  20.         }
  21.     }
  22.  
  23.     class SoftUniKaraoke
  24.     {
  25.         static void Main(string[] args)
  26.         {
  27.             List<Singer> singers = new List<Singer>();
  28.             List<string> givenAwards = new List<string>();
  29.  
  30.             string[] inputSingers = Console.ReadLine().Split(new char[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);
  31.             string[] inputSongs = Console.ReadLine().Split(',');
  32.             List<string> songs = new List<string>();
  33.  
  34.             foreach (string song in inputSongs)
  35.             {
  36.                 songs.Add(song.Trim());
  37.             }
  38.  
  39.             while (true)
  40.             {
  41.                 string input = Console.ReadLine();
  42.                 if (input.ToLower() == "dawn") break;
  43.  
  44.                 string[] inputArgs = input.Split(',');
  45.                 string currentSinger = inputArgs[0].Trim();
  46.                 string currentSong = inputArgs[1].Trim();
  47.                 string currentAward = inputArgs[2].Trim();
  48.  
  49.                 if (!inputSingers.Contains(currentSinger)) continue;
  50.  
  51.                 if (!songs.Contains(currentSong)) continue;
  52.  
  53.                 Singer curr = new Singer();
  54.                 if (singers.Any(x => x.Name == currentSinger))
  55.                 {
  56.                     curr = singers.First(x => x.Name == currentSinger);
  57.                     if (!curr.Songs.Contains(currentSong))
  58.                     {
  59.                         curr.Songs.Add(currentSong);
  60.                     }
  61.                     if (!curr.Awards.Contains(currentAward) && !givenAwards.Contains(currentAward))
  62.                     {
  63.                         curr.Awards.Add(currentAward);
  64.                     }
  65.                 }
  66.                 else
  67.                 {
  68.                     curr = new Singer();
  69.                     curr.Name = currentSinger;
  70.                     curr.Songs.Add(currentSong);
  71.                     if (!givenAwards.Contains(currentAward))
  72.                     {
  73.                         curr.Awards.Add(currentAward);
  74.                     }
  75.                     singers.Add(curr);
  76.                 }
  77.  
  78.                 givenAwards.Add(currentAward);
  79.             }
  80.  
  81.             foreach (Singer singer in singers.OrderByDescending(x => x.Awards.Count).ThenBy(x => x.Name))
  82.             {
  83.                 Console.WriteLine("{0}: {1} awards", singer.Name, singer.Awards.Count);
  84.                 foreach (string award in singer.Awards.OrderBy(x => x))
  85.                 {
  86.                     Console.WriteLine("--{0}", award);
  87.                 }
  88.             }
  89.  
  90.             if (singers.Count == 0)
  91.             {
  92.                 Console.WriteLine("No awards");
  93.             }
  94.         }
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement