Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Orders_ExercisesAssArrays
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, decimal> productPrices = new Dictionary<string, decimal>();
- Dictionary<string, long> productQuantity = new Dictionary<string, long>();
- string input;
- while ((input = Console.ReadLine()) != "buy")
- {
- string[] productArgs = input
- .Split(' ', StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- string name = productArgs[0];
- decimal price = decimal.Parse(productArgs[1]);
- int quantity = int.Parse(productArgs[2]);
- if (!productQuantity.ContainsKey(name))
- {
- productQuantity[name] = 0;
- productPrices[name] = 0;
- }
- productQuantity[name] += quantity;
- productPrices[name] = price;
- }
- foreach (var kvp in productPrices)
- {
- string name = kvp.Key;
- decimal price = kvp.Value;
- long quantity = productQuantity[name];
- decimal totalProducts = price * quantity;
- Console.WriteLine($"{name} -> {totalProducts:f2}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement