Advertisement
Niicksana

Product Shop

Sep 30th, 2018
797
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03._Product_Shop
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             // 03.  Product Shop - Sets and Dictionaries Advanced - Lab
  12.            
  13.             Dictionary<string, Dictionary<string, double>> productShops = new Dictionary<string, Dictionary<string, double>>();
  14.  
  15.             string[] info = Console.ReadLine().Split(", ", StringSplitOptions.RemoveEmptyEntries);
  16.  
  17.             while (info[0] != "Revision")
  18.             {
  19.                 string shop = info[0];
  20.                 string product = info[1];
  21.                 double price = double.Parse(info[2]);
  22.  
  23.                 if (!productShops.ContainsKey(shop))
  24.                 {
  25.                     productShops.Add(shop, new Dictionary<string, double>());
  26.                 }
  27.  
  28.                 if (!productShops[shop].ContainsKey(product))
  29.                 {
  30.                     productShops[shop].Add(product, 0);
  31.                 }
  32.  
  33.                 productShops[shop][product] = price;          
  34.  
  35.                 info = Console.ReadLine().Split(", ", StringSplitOptions.RemoveEmptyEntries);
  36.             }
  37.  
  38.             foreach (var shop in productShops.OrderBy(shop => shop.Key))
  39.             {
  40.                 Console.WriteLine($"{shop.Key}->");
  41.  
  42.                 foreach (var product in shop.Value)
  43.                 {
  44.                     Console.WriteLine($"Product: {product.Key}, Price: {product.Value}");
  45.                 }
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement