Advertisement
YavorGrancharov

Camping(lambda)

Jul 22nd, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Camping
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Dictionary<string, Dictionary<string, int>> regCampers =
  12.                 new Dictionary<string, Dictionary<string, int>>();
  13.  
  14.             string[] input = Console.ReadLine().Split(' ');
  15.  
  16.             while (input[0] != "end")
  17.             {
  18.                 string persons = input[0];
  19.                 string camperModel = input[1];
  20.                 int nights = int.Parse(input[2]);
  21.  
  22.                 if (!regCampers.ContainsKey(persons))
  23.                 {
  24.                     regCampers.Add(persons, new Dictionary<string, int>());
  25.                 }
  26.                 regCampers[persons][camperModel] = nights;
  27.  
  28.                 input = Console.ReadLine().Split(' ');
  29.             }
  30.            
  31.             foreach (var person in regCampers
  32.             .OrderByDescending(p => p.Value.Count())
  33.             .ThenBy(p => p.Key.Length))
  34.             {
  35.                 int sumNights = 0;
  36.  
  37.                 string personName = person.Key;
  38.                 int countDup = person.Value.Count();
  39.  
  40.                 Dictionary<string, int> campers = person.Value;
  41.                
  42.                 Console.WriteLine("{0}: {1}", personName, countDup);
  43.  
  44.                 foreach (var camper in campers)
  45.                 {
  46.                     string camperModel = camper.Key;
  47.                     Console.WriteLine("***{0}", camperModel);
  48.                     int nights = camper.Value;
  49.                     sumNights += nights;                    
  50.                 }
  51.                 Console.WriteLine("Total stay: {0} nights", sumNights);
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement