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 _03LinqExcercisesshoppingSpree
- {
- class Program
- {
- static void Main(string[] args)
- {
- decimal peshoMoney = decimal.Parse(Console.ReadLine());
- Dictionary<string, decimal> shopingList = new Dictionary<string, decimal>();
- string products = Console.ReadLine();
- while (products != "end")
- {
- string[] inputTokens = products.Split(' ').ToArray();
- string product = inputTokens[0];
- decimal productPrice = decimal.Parse(inputTokens[1]);
- shopingList[product] = productPrice;
- products = Console.ReadLine();
- }
- decimal totalsum = 0;
- foreach (decimal value in shopingList.Values)
- {
- totalsum += value;
- }
- if (Math.Round(totalsum,2) <= peshoMoney)
- {
- foreach (KeyValuePair<string, decimal> pair in shopingList
- .OrderByDescending(x => x.Value)
- .ThenBy(x => x.Key.Length))
- {
- Console.WriteLine($"{pair.Key} costs {pair.Value:f2}");
- }
- }
- else
- {
- Console.WriteLine("Need more money... Just buy banichka");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment