Advertisement
Guest User

Untitled

a guest
Jul 30th, 2022
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P02.SoftUniKaraoke
  6. {
  7.     internal class SoftUniKaraoke
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string[] participants = Console.ReadLine()
  12.                 .Split(',').Select(p => p.Trim()).ToArray();
  13.             string[] songs = Console.ReadLine()
  14.                 .Split(',').Select(p => p.Trim()).ToArray();
  15.             string command = Console.ReadLine();
  16.  
  17.             var participantsAwards = new Dictionary<string, List<string>>();
  18.  
  19.             while (command != "dawn")
  20.             {
  21.                 string[] info = command
  22.                     .Split(',').Select(p => p.Trim()).ToArray();
  23.  
  24.                 string participant = info[0];
  25.                 string song = info[1];
  26.  
  27.                 if (participants.Contains(participant) && songs.Contains(song))
  28.                 {
  29.                     string award = info[2];
  30.  
  31.                     if (!participantsAwards.ContainsKey(participant))
  32.                     {
  33.                         participantsAwards.Add(participant, new List<string>() { award });
  34.                     }
  35.                     else if (!participantsAwards[participant].Contains(award))
  36.                     {
  37.                         participantsAwards[participant].Add(award);
  38.                     }
  39.                 }
  40.  
  41.                 command = Console.ReadLine();
  42.             }
  43.  
  44.             if (participantsAwards.Count == 0)
  45.             {
  46.                 Console.WriteLine("No awards");
  47.             }
  48.             else
  49.             {
  50.                 participantsAwards = participantsAwards
  51.                     .OrderByDescending(a => a.Value.Count)
  52.                     .ThenBy(p => p.Key)
  53.                     .ToDictionary(p => p.Key, a => a.Value);
  54.  
  55.                 foreach (var participantAwards in participantsAwards)
  56.                 {
  57.                     Console.WriteLine($"{participantAwards.Key}: {participantAwards.Value.Count} awards");
  58.  
  59.                     participantAwards.Value.Sort();
  60.  
  61.                     foreach (string award in participantAwards.Value)
  62.                     {
  63.                         Console.WriteLine($"--{award}");
  64.                     }
  65.                 }
  66.             }
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement