Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Exam
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- public class SoftUniKaraoke
- {
- static void Main()
- {
- string[] allParticipants = Regex.Split(Console.ReadLine(), @"\s*,\s*");
- string[] allSongs = Console.ReadLine().Split(',').Select(s => s.Trim()).ToArray();
- var awardsByParticipant = new Dictionary<string, HashSet<string>>(); //name, awards(unique)
- foreach(var p in allParticipants)
- {
- awardsByParticipant[p] = new HashSet<string>();
- }
- while (true)
- {
- var line = Console.ReadLine();
- if (line == "dawn")
- {
- break;
- }
- var tokens = Regex.Split(line, @"\s*,\s*");
- var participant = tokens[0];
- var song = tokens[1];
- var award = tokens[2];
- if (allParticipants.Contains(participant) && allSongs.Contains(song))
- {
- awardsByParticipant[participant].Add(award);
- }
- }
- var result = awardsByParticipant.Select(item => new
- {
- playerName = item.Key,
- awards = item.Value.Distinct().OrderBy(a => a),
- awardsCount = item.Value.Distinct().Count()
- })
- .OrderByDescending(p => p.awardsCount) //sort by awards count in descending order
- .ThenBy(p => p.playerName) //sort alphabetically by name
- .Where(p => p.awardsCount > 0) //remove people with 0 awards
- .ToArray();
- foreach(var p in result)
- {
- Console.WriteLine(p.playerName + ": " + p.awardsCount + " awards");
- foreach(var aw in p.awards)
- {
- Console.WriteLine("--" + aw);
- }
- }
- if(result.Length == 0)
- {
- Console.WriteLine("No awards");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement