Advertisement
gabi11

Sets & Dictionaries Advanced - 3. Product Shop

May 18th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace Advanced
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var shops = new SortedDictionary<string, Dictionary<string, double>>();
  14.  
  15.             while (true)
  16.             {
  17.                 var input = Console.ReadLine();
  18.  
  19.                 if (input == "Revision")
  20.                 {
  21.                     break;
  22.                 }
  23.  
  24.                 var details = input.Split(", ");
  25.  
  26.                 var shop = details[0];
  27.                 var product = details[1];
  28.                 var price = double.Parse(details[2]);
  29.  
  30.                 if (!shops.ContainsKey(shop))
  31.                 {
  32.                     shops[shop] = new Dictionary<string, double>();
  33.                 }
  34.  
  35.                 shops[shop][product] = price;
  36.             }
  37.  
  38.             foreach (var shop in shops)
  39.             {
  40.                 var shopName = shop.Key;
  41.                 var products = shop.Value;
  42.  
  43.                 Console.WriteLine($"{shopName}->");
  44.  
  45.                 foreach (var product in products)
  46.                 {
  47.                     Console.WriteLine($"Product: {product.Key}, Price: {product.Value}");
  48.                 }
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement