Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp53
- {
- class Program
- {
- class Item
- {
- public double price;
- public double quantity;
- public Item(double p, double q)
- {
- price = p;
- quantity = q;
- }
- public double GetTotalPrice()
- {
- return price * quantity;
- }
- public void UpdateQuantityAndPrice(double price, double newQuantity)
- {
- quantity += newQuantity;
- this.price = price;
- }
- }
- static void Main(string[] args)
- {
- var orders = new Dictionary<String, Item>();
- string input = string.Empty;
- while ((input = Console.ReadLine()) != "buy")
- {
- string[] inputStrings = input.Split();
- if (!orders.ContainsKey(inputStrings[0]))
- {
- Item item = new Item(double.Parse(inputStrings[1]), double.Parse(inputStrings[2]));
- orders.Add(inputStrings[0], item);
- }
- else
- {
- Item curItem = orders[inputStrings[0]];
- curItem.UpdateQuantityAndPrice(double.Parse(inputStrings[1]), double.Parse(inputStrings[2]));
- }
- }
- foreach (var kvp in orders)
- {
- Console.WriteLine($"{kvp.Key} -> {kvp.Value.GetTotalPrice():F2}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement