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 Product
- {
- public int Quantity { get; set; }
- public string Name { get; set; }
- public double Price { get; set; }
- public Product(int quantity, double price)
- {
- Quantity = quantity;
- Price = price;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, Product> dict = new Dictionary<string, Product>();
- string comand = Console.ReadLine();
- while (comand != "buy")
- {
- string[] input = comand.Split();
- string name = input[0];
- double price = double.Parse(input[1]);
- int quantity = int.Parse(input[2]);
- if (!dict.ContainsKey(name))
- {
- dict[name] = new Product(quantity, price);
- }
- else
- {
- dict[name].Quantity += quantity;
- dict[name].Price = price;
- }
- comand = Console.ReadLine();
- }
- foreach (var item in dict)
- {
- Console.WriteLine($"{item.Key} -> {(item.Value.Price * item.Value.Quantity):f2}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment