Advertisement
Guest User

Exam 3

a guest
Jan 22nd, 2018
101
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.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Numerics;
  7. namespace VII_03_Exam
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             SortedDictionary<string, Dictionary<string, long>> Persons = new SortedDictionary<string, Dictionary<string, long>>();
  14.             while (true)
  15.             {
  16.                 string command = Console.ReadLine();
  17.                 if (command == "End") break;
  18.                 var tmp = command.Split(new string[] { "->" }, StringSplitOptions.RemoveEmptyEntries);
  19.                 string name = tmp[0];
  20.                 tmp = tmp[1].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
  21.                 string liquidname = tmp[0];
  22.                 long jarcount = long.Parse(tmp[1]);
  23.  
  24.                 if (!Persons.ContainsKey(name))
  25.                 {
  26.                     Persons.Add(name, new Dictionary<string, long>());
  27.                 }
  28.                 if (!Persons[name].ContainsKey(liquidname))
  29.                 {
  30.                     Persons[name].Add(liquidname, 0);
  31.                 }
  32.                 Persons[name][liquidname] += jarcount;
  33.             }
  34.             foreach (var Person in Persons)
  35.             {
  36.                 Console.WriteLine($"{Person.Key}Liquids:");
  37.                 var sortedcount = from entry in Person.Value orderby entry.Value ascending select entry;
  38.                 foreach (var liquid in sortedcount)
  39.                 {
  40.                     Console.WriteLine($"---{liquid.Key}: {liquid.Value}");
  41.                 }
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement