Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- Dictionary<string, List<double>> products = new Dictionary<string, List<double>>();
- while (input != "buy")
- {
- string[] productInfo = input.Split();
- string currentProduct = productInfo[0];
- double priceForOneProduct = double.Parse(productInfo[1]);
- double quantity = double.Parse(productInfo[2]);
- if (!products.ContainsKey(currentProduct))
- {
- products.Add(currentProduct, new List<double> {priceForOneProduct, quantity});
- }
- else
- {
- foreach (var product in products)
- {
- if (product.Key == currentProduct)
- {
- product.Value[0] = priceForOneProduct;
- product.Value[1] += quantity;
- }
- }
- }
- input = Console.ReadLine();
- }
- foreach (var product in products)
- {
- product.Value[0] = product.Value[0] * product.Value[1];
- Console.WriteLine($"{product.Key} -> {product.Value[0]:f2}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement