Advertisement
Guest User

Сръбско Unleashed

a guest
Feb 18th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _10._Srabsko_Unleashed
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var srabskoList = new Dictionary<string, Dictionary<string, int>>();
  12.  
  13.             string line;
  14.  
  15.             while ((line = Console.ReadLine()) != "End")
  16.             {
  17.                 string[] tokens = line
  18.                     .Split(" @");
  19.  
  20.                 if (tokens.Length != 2)
  21.                 {
  22.                     continue;
  23.                 }
  24.  
  25.                 string name = tokens[0];
  26.  
  27.                 string[] temp = tokens[1]
  28.                     .Split();
  29.  
  30.                 int tempLenght = temp.Length;
  31.  
  32.                 if (tempLenght < 3)
  33.                 {
  34.                     continue;
  35.                 }
  36.  
  37.                 int price = int.Parse(temp[tempLenght - 2]);
  38.                 int count = int.Parse(temp[tempLenght - 1]);
  39.  
  40.                 string venues = string.Join(" ", temp.Take(tempLenght - 2));
  41.  
  42.                 if (!srabskoList.ContainsKey(venues))
  43.                 {
  44.                     srabskoList.Add(venues, new Dictionary<string, int>());
  45.                 }
  46.  
  47.                 if (!srabskoList[venues].ContainsKey(name))
  48.                 {
  49.                     srabskoList[venues][name] = price * count;
  50.                 }
  51.                 else
  52.                 {
  53.                     srabskoList[venues][name] += price * count;
  54.                 }
  55.             }
  56.  
  57.             foreach (var srabskoPerTawn in srabskoList)
  58.             {
  59.                 Console.WriteLine(srabskoPerTawn.Key);
  60.  
  61.                 foreach (var singerPerPrice in srabskoPerTawn.Value.OrderByDescending(x => x.Value))
  62.                 {
  63.                     Console.WriteLine("#  " + singerPerPrice.Key + " -> " + singerPerPrice.Value);
  64.                 }
  65.             }
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement