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