Advertisement
Guest User

Concert

a guest
Apr 1st, 2019
876
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.00 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace ConsoleApp6
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string command = string.Empty;
  12.             var bandsMembers = new Dictionary<string, List<string>>();
  13.             var bandsTimes = new Dictionary<string, int>();
  14.  
  15.             while ((command = Console.ReadLine()) != "start of concert")
  16.             {
  17.                 List<string> commandList = command.Split("; " ).ToList();
  18.  
  19.                 if (commandList[0] == "Add")
  20.                 {
  21.                     string[] members = commandList[2].Split(", ");
  22.                     commandList.RemoveAt(2);
  23.  
  24.                     GetResultByADD(members, commandList, bandsMembers, bandsTimes);                    
  25.                 }
  26.                 else if (commandList[0] == "Play")
  27.                 {
  28.                     GetResultByPlayCommand(bandsMembers, commandList, bandsTimes);                    
  29.                 }
  30.             }
  31.             PrintResult(bandsTimes, bandsMembers);          
  32.         }
  33.  
  34.         private static void GetResultByADD(string[] members, List<string> commandList, Dictionary<string, List<string>> bandsMembers, Dictionary<string, int> bandsTimes)
  35.         {
  36.             for (int i = 0; i < members.Length; i++)
  37.             {
  38.                 commandList.Add(members[i]);
  39.             }
  40.  
  41.  
  42.             if (!bandsMembers.ContainsKey(commandList[1]))
  43.             {
  44.                 bandsMembers.Add(commandList[1], new List<string>());
  45.                 bandsTimes.Add(commandList[1], 0);
  46.             }
  47.             for (int i = 2; i < commandList.Count; i++)
  48.             {
  49.                 if (!bandsMembers[commandList[1]].Contains(commandList[i]))
  50.                 {
  51.                     bandsMembers[commandList[1]].Add(commandList[i]);
  52.                 }
  53.             }
  54.         }
  55.  
  56.         private static void GetResultByPlayCommand(Dictionary<string, List<string>> bandsMembers, List<string> commandList, Dictionary<string, int> bandsTimes)
  57.         {
  58.             if (!bandsMembers.ContainsKey(commandList[1]))
  59.             {
  60.                 bandsMembers.Add(commandList[1], new List<string>());
  61.                 bandsTimes.Add(commandList[1], 0);
  62.             }
  63.             bandsTimes[commandList[1]] += int.Parse(commandList[2]);
  64.         }
  65.  
  66.         private static void PrintResult(Dictionary<string, int> bandsTimes, Dictionary<string, List<string>> bandsMembers)
  67.         {
  68.             string bandToBeWriten = Console.ReadLine();
  69.  
  70.             Console.WriteLine($"Total time: {bandsTimes.Values.Sum()}");
  71.  
  72.             foreach (var kvp in bandsTimes.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  73.             {
  74.                 Console.WriteLine($"{kvp.Key} -> {kvp.Value}");
  75.             }
  76.  
  77.  
  78.             Console.WriteLine(bandToBeWriten);
  79.  
  80.             foreach (var member in bandsMembers[bandToBeWriten])
  81.             {
  82.                 Console.WriteLine($"=> {member}");
  83.             }
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement