Advertisement
Guest User

Untitled

a guest
Jan 15th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace SRABSKO
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<string, Dictionary<string, long>> dict = new Dictionary<string, Dictionary<string, long>>();
  14.  
  15.             while (true)
  16.             {
  17.                 string inputLine = Console.ReadLine();
  18.                 if (inputLine.Equals("End"))
  19.                 {
  20.                     break;
  21.                 }
  22.  
  23.                 if (!inputLine.Contains("@"))
  24.                 {
  25.                     continue;
  26.                 }
  27.  
  28.                 string[] singerArgs = inputLine.Split('@');
  29.                 string singerName = singerArgs[0].Trim();
  30.                 string[] concertArgs = singerArgs[1].Split(' ');
  31.  
  32.                 if (concertArgs.Length < 3 || !singerArgs[0].EndsWith(" "))
  33.                 {
  34.                     continue;
  35.                 }
  36.                 int ticketsCount = 0;
  37.                 int ticketsPrice = 0;
  38.                 try
  39.                 {
  40.                     ticketsCount = int.Parse(concertArgs[concertArgs.Length - 1]);
  41.                     ticketsPrice = int.Parse(concertArgs[concertArgs.Length - 2]);
  42.                 }
  43.                 catch (Exception)
  44.                 {
  45.                     continue;
  46.                 }
  47.  
  48.                 string venue = "";
  49.                 for (int i = 0; i < concertArgs.Length - 2; i++)
  50.                 {
  51.                     venue += concertArgs[i] + " ";
  52.                 }
  53.                 venue = venue.TrimEnd();
  54.  
  55.                 if (!dict.ContainsKey(venue))
  56.                 {
  57.                     dict.Add(venue, new Dictionary<string, long>());
  58.                 }
  59.  
  60.                 if (!dict[venue].ContainsKey(singerName))
  61.                 {
  62.                     dict[venue].Add(singerName, 0);
  63.                 }
  64.                 dict[venue][singerName] += (long)ticketsPrice * ticketsCount;
  65.             }
  66.  
  67.             foreach (var venue in dict)
  68.             {
  69.                 Console.WriteLine(venue.Key);
  70.                 foreach (var singer in dict[venue.Key].OrderByDescending(x => x.Value))
  71.                 {
  72.                     Console.WriteLine($"#  {singer.Key} -> {singer.Value}");
  73.                 }
  74.             }
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement