Advertisement
ralichka

AssociativeArrays-04.Orders

Nov 18th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04.Orders
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> input = Console.ReadLine().Split().ToList();
  12.  
  13.             string name = input[0];
  14.  
  15.             Dictionary<string, PriceAndQuantity> dict = new Dictionary<string, PriceAndQuantity>();
  16.  
  17.             while (name != "buy")
  18.             {
  19.                 double price = double.Parse(input[1]);
  20.                 int quantity = int.Parse(input[2]);
  21.  
  22.                 if (!dict.ContainsKey(name))
  23.                 {
  24.                     dict[name] = new PriceAndQuantity();
  25.                 }
  26.                
  27.                
  28.                     dict[name].PriceProduct = price;
  29.                     dict[name].QuantityProduct += quantity;
  30.                
  31.  
  32.                 input = Console.ReadLine().Split().ToList();
  33.                 name = input[0];
  34.  
  35.             }
  36.  
  37.             foreach (var item in dict)
  38.             {
  39.                 var totalPrice = item.Value.PriceProduct * item.Value.QuantityProduct;
  40.                 Console.WriteLine($"{item.Key} -> {totalPrice:f2}");
  41.             }
  42.  
  43.         }
  44.         class PriceAndQuantity
  45.         {
  46.             public double PriceProduct { get; set; }
  47.             public int QuantityProduct { get; set; }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement