Advertisement
Guest User

Сръбско Unleashed

a guest
Apr 18th, 2018
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace СръбскоUnleashed
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Dictionary<string, Dictionary<string, int>> venueSingerIncome = new Dictionary<string, Dictionary<string, int>>();
  12.             string[] input = new string[2];
  13.            
  14.             string venue = "";
  15.             string singer = "";
  16.             int ticketPrice = 0;
  17.             int ticketCount = 0;
  18.             int totalIncome = 0;
  19.  
  20.             while (input[0] != "End")
  21.             {
  22.                 input = Console.ReadLine().Split('@').ToArray();
  23.                 try
  24.                 {
  25.                     singer = input[0];
  26.                     List<string> theRest = input[1].Split(' ').ToList();
  27.                     ticketCount = int.Parse(theRest[theRest.Count - 1]);
  28.                     theRest.RemoveAt(theRest.Count - 1);
  29.                     ticketPrice = int.Parse(theRest[theRest.Count - 1]);
  30.                     theRest.RemoveAt(theRest.Count - 1);
  31.                     totalIncome = ticketCount * ticketPrice;
  32.                     venue = string.Join(" ", theRest);
  33.                 }
  34.                 catch (Exception)
  35.                 {
  36.                     continue;
  37.                 }
  38.                 if (!venueSingerIncome.ContainsKey(venue))
  39.                 {
  40.                     Dictionary<string, int> singerIncome = new Dictionary<string, int>();
  41.                     singerIncome.Add(singer, totalIncome);
  42.                     venueSingerIncome.Add(venue, singerIncome);
  43.                 }
  44.                 else
  45.                 {
  46.                     if (!venueSingerIncome[venue].ContainsKey(singer))
  47.                     {
  48.                         venueSingerIncome[venue].Add(singer, totalIncome);
  49.                     }
  50.                     else
  51.                     {
  52.                         venueSingerIncome[venue][singer] += totalIncome;
  53.                     }
  54.                 }
  55.             }
  56.             foreach (var pair in venueSingerIncome)
  57.             {
  58.                 Console.WriteLine(pair.Key);
  59.                 foreach (var kvp in pair.Value.OrderByDescending(x=>x.Value))
  60.                 {
  61.                     Console.WriteLine($"#  {kvp.Key}-> {kvp.Value}");
  62.                 }
  63.             }
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement