Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 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 _5._03.Camping
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.             var result = new Dictionary<string, Dictionary<string, int>>();
  15.            
  16.             while (input != "end")
  17.             {
  18.                 string[] inputTokens = input.Split(' ').ToArray();
  19.                 string personName = inputTokens[0];
  20.                 string camperModel = inputTokens[1];
  21.                 int timeToStay = int.Parse(inputTokens[2]);
  22.  
  23.                 if (!result.ContainsKey(personName))
  24.                 {
  25.                     result.Add(personName, new Dictionary<string, int>());
  26.                 }
  27.                 result[personName].Add(camperModel, timeToStay);
  28.                
  29.                 input = Console.ReadLine();
  30.             }
  31.            
  32.             foreach (var person in result.OrderByDescending(c => c.Value.Count()).ThenBy(p => p.Key))
  33.             {
  34.                 string personName = person.Key;
  35.                 int countOfRvs = person.Value.Count();
  36.                 int totalNights = 0;
  37.  
  38.                 Console.WriteLine($"{personName}: {countOfRvs}");
  39.                 foreach (var item in person.Value)
  40.                 {
  41.                     string nameOfRv = item.Key;
  42.                     int nights = item.Value;
  43.                     Console.WriteLine($"***{nameOfRv}");
  44.                     totalNights += nights;
  45.                 }
  46.                 Console.WriteLine($"Total stay: {totalNights} nights");
  47.  
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement