Advertisement
DyNaMiXx7

Untitled

Mar 25th, 2019
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 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.             var pricesOfProducts = new Dictionary<string, double>();
  13.  
  14.             string input = string.Empty;
  15.             while ((input = Console.ReadLine()) != "buy")
  16.             {
  17.                 string[] productInfo = input.Split();
  18.                 string productName = productInfo[0];
  19.                 double productPrice = double.Parse(productInfo[1]);
  20.                 double productQuantity = double.Parse(productInfo[2]);
  21.  
  22.                 if (!products.ContainsKey(productName))
  23.                 {
  24.                     products.Add(productName, productQuantity);
  25.                 }
  26.                 else
  27.                 {
  28.                     products[productName] += productQuantity;
  29.                 }
  30.  
  31.                 if (!pricesOfProducts.ContainsKey(productName))
  32.                 {
  33.                     pricesOfProducts.Add(productName, productPrice);
  34.                 }
  35.                 else
  36.                 {
  37.                     pricesOfProducts[productName] = productPrice;
  38.                 }
  39.  
  40.                 products.Select(x => x.Value * productPrice).ToDictionary(x => x, x => true);
  41.             }
  42.  
  43.             foreach (var kvp in products)
  44.             {
  45.                 Console.WriteLine($"{kvp.Key} -> {kvp.Value:F2}");
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement