Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ITCareer_OOP_Exam_1
- {
- class Program
- {
- static void Main(string[] args)
- {
- //до получаване на Stop shopping -> четем стринг
- string input = Console.ReadLine();
- Dictionary<string, double> products = new Dictionary<string, double>();
- double totalSum = 0;
- while(input != "Stop shopping")
- {
- //"milk-1.2" -> ["milk", "1.20"]
- string productName = input.Split("-")[0];
- double productPrice = double.Parse(input.Split("-")[1]);
- totalSum += productPrice;
- //1. да имаме продукта
- if (products.ContainsKey(productName))
- {
- products[productName] = products[productName] + productPrice;
- }
- //2. да го нямаме
- else
- {
- products.Add(productName, productPrice);
- }
- input = Console.ReadLine();
- }
- var sorted = products.OrderBy(pair => pair.Value);
- foreach(var pair in sorted)
- {
- Console.WriteLine($"{pair.Key} -> {pair.Value:F2}");
- }
- Console.WriteLine($"Total sum: {totalSum:F2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement