Advertisement
YavorGrancharov

Shellbound(copy)

Jul 14th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Shellbound
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Dictionary<string, HashSet<int>> stock = new Dictionary<string, HashSet<int>>();
  12.             string input = Console.ReadLine();
  13.  
  14.             while (input != "Aggregate")
  15.             {
  16.                 string[] tokens = input.Split(' ');
  17.                 string city = tokens[0];
  18.                 int size = int.Parse(tokens[1]);
  19.                 if (!stock.ContainsKey(city))
  20.                 {
  21.                     stock[city] = new HashSet<int>();
  22.                 }
  23.                 stock[city].Add(size);
  24.  
  25.                 input = Console.ReadLine();
  26.             }
  27.             foreach (var shell in stock)
  28.             {
  29.                 string city = shell.Key;
  30.                 HashSet<int> shellSize = shell.Value;
  31.                 Console.WriteLine($"{city} -> {string.Join(", ", shellSize)} ({Math.Ceiling(shellSize.Sum() - shellSize.Average())})");
  32.             }
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement