Advertisement
red_dragon_1

4.Orders AssociativeArrays

Jul 6th, 2019
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5.  
  6. namespace _4.Orders
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             var dict = new Dictionary<string, List<double>>();
  13.  
  14.             while (true)
  15.             {
  16.                 var arrayCommand = Console.ReadLine()
  17.                     .Split()
  18.                     .ToList();
  19.                 if (arrayCommand[0] == "buy")
  20.                 {
  21.                     break;
  22.                 }
  23.  
  24.                 string command = arrayCommand[0];
  25.                 double priceValue = double.Parse(arrayCommand[1]);
  26.                 double quantityValue = double.Parse(arrayCommand[2]);
  27.  
  28.                 if (!dict.ContainsKey(command))
  29.                 {
  30.  
  31.                     dict.Add(command, new List<double>());
  32.                 }
  33.  
  34.                
  35.                 dict[command].Add(priceValue);
  36.               // here's the issue  dict[command].Insert(1, quantityValue);
  37.                 // how to add the sum at index 1 of the list(values) ? The calculation above is incorrect;
  38.                 //listProduct[product][1] += quantity;= that does not work
  39.                 // with lists , only with [](array)
  40.  
  41.             }
  42.             foreach (var item in dict)
  43.             {
  44.                 Console.WriteLine($"{item.Key} -> {(item.Value[0] * item.Value[1]):f2}");
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement