Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace P02.SoftUniKaraoke
- {
- internal class SoftUniKaraoke
- {
- static void Main(string[] args)
- {
- string[] participants = Console.ReadLine()
- .Split(',').Select(p => p.Trim()).ToArray();
- string[] songs = Console.ReadLine()
- .Split(',').Select(p => p.Trim()).ToArray();
- string command = Console.ReadLine();
- var participantsAwards = new Dictionary<string, List<string>>();
- while (command != "dawn")
- {
- string[] info = command
- .Split(',').Select(p => p.Trim()).ToArray();
- string participant = info[0];
- string song = info[1];
- if (participants.Contains(participant) && songs.Contains(song))
- {
- string award = info[2];
- if (!participantsAwards.ContainsKey(participant))
- {
- participantsAwards.Add(participant, new List<string>() { award });
- }
- else if (!participantsAwards[participant].Contains(award))
- {
- participantsAwards[participant].Add(award);
- }
- }
- command = Console.ReadLine();
- }
- if (participantsAwards.Count == 0)
- {
- Console.WriteLine("No awards");
- }
- else
- {
- participantsAwards = participantsAwards
- .OrderByDescending(a => a.Value.Count)
- .ThenBy(p => p.Key)
- .ToDictionary(p => p.Key, a => a.Value);
- foreach (var participantAwards in participantsAwards)
- {
- Console.WriteLine($"{participantAwards.Key}: {participantAwards.Value.Count} awards");
- participantAwards.Value.Sort();
- foreach (string award in participantAwards.Value)
- {
- Console.WriteLine($"--{award}");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement