Advertisement
svetlyoek

Untitled

Mar 14th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleApp205
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string command = string.Empty;
  12. Dictionary<string, double[]> dict = new Dictionary<string,double[]>();
  13. while ((command=Console.ReadLine())!="buy")
  14. {
  15.  
  16. string[] text =command.Split().ToArray();
  17.  
  18. string product = text[0];
  19. double price = double.Parse(text[1]);
  20. int quantity = int.Parse(text[2]);
  21. if(!dict.ContainsKey(product))
  22. {
  23. dict.Add(product,new double[2]);
  24. }
  25. dict[product][0] = price;
  26. dict[product][1] += quantity;
  27.  
  28.  
  29.  
  30. }
  31. foreach(var item in dict)
  32. {
  33. Console.WriteLine($"{item.Key} -> {(item.Value[0]*item.Value[1]):f2}");
  34. }
  35.  
  36.  
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement