Advertisement
gospod1978

Exam\Concert

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