Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Lists
- {
- class Program
- {
- static void Main(string[] args)
- {
- SortedDictionary<string, double> shopCart = new SortedDictionary<string, double>();
- double total = 0;
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "STOP SHOPPING")
- {
- break;
- }
- string[] input = command.Split('-').ToArray();
- string product = input[0];
- double price = double.Parse(input[1]);
- total += price;
- if (shopCart.ContainsKey(product))
- {
- shopCart[product] += price;
- }
- else
- {
- shopCart.Add(product, price);
- }
- }
- foreach (var item in shopCart)
- {
- Console.WriteLine($"{item.Key}->{item.Value}");
- }
- Console.WriteLine($"{total:F2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement