Advertisement
nikolayneykov

Untitled

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