Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _04.Orders
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> input = Console.ReadLine().Split().ToList();
- string name = input[0];
- Dictionary<string, PriceAndQuantity> dict = new Dictionary<string, PriceAndQuantity>();
- while (name != "buy")
- {
- double price = double.Parse(input[1]);
- int quantity = int.Parse(input[2]);
- if (!dict.ContainsKey(name))
- {
- dict[name] = new PriceAndQuantity();
- }
- dict[name].PriceProduct = price;
- dict[name].QuantityProduct += quantity;
- input = Console.ReadLine().Split().ToList();
- name = input[0];
- }
- foreach (var item in dict)
- {
- var totalPrice = item.Value.PriceProduct * item.Value.QuantityProduct;
- Console.WriteLine($"{item.Key} -> {totalPrice:f2}");
- }
- }
- class PriceAndQuantity
- {
- public double PriceProduct { get; set; }
- public int QuantityProduct { get; set; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement