Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _5._03.Camping
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- var result = new Dictionary<string, Dictionary<string, int>>();
- while (input != "end")
- {
- string[] inputTokens = input.Split(' ').ToArray();
- string personName = inputTokens[0];
- string camperModel = inputTokens[1];
- int timeToStay = int.Parse(inputTokens[2]);
- if (!result.ContainsKey(personName))
- {
- result.Add(personName, new Dictionary<string, int>());
- }
- result[personName].Add(camperModel, timeToStay);
- input = Console.ReadLine();
- }
- foreach (var person in result.OrderByDescending(c => c.Value.Count()).ThenBy(p => p.Key))
- {
- string personName = person.Key;
- int countOfRvs = person.Value.Count();
- int totalNights = 0;
- Console.WriteLine($"{personName}: {countOfRvs}");
- foreach (var item in person.Value)
- {
- string nameOfRv = item.Key;
- int nights = item.Value;
- Console.WriteLine($"***{nameOfRv}");
- totalNights += nights;
- }
- Console.WriteLine($"Total stay: {totalNights} nights");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement