Aliendreamer

shoppingSpree

Jul 16th, 2017
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _03LinqExcercisesshoppingSpree
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             decimal peshoMoney = decimal.Parse(Console.ReadLine());
  15.  
  16.             Dictionary<string, decimal> shopingList = new Dictionary<string, decimal>();
  17.  
  18.             string products = Console.ReadLine();
  19.  
  20.             while (products != "end")
  21.             {
  22.  
  23.                 string[] inputTokens = products.Split(' ').ToArray();
  24.                 string product = inputTokens[0];
  25.                 decimal productPrice = decimal.Parse(inputTokens[1]);
  26.  
  27.                 shopingList[product] = productPrice;
  28.  
  29.                 products = Console.ReadLine();
  30.  
  31.             }
  32.             decimal totalsum = 0;
  33.  
  34.             foreach (decimal value in shopingList.Values)
  35.             {
  36.                 totalsum += value;
  37.             }
  38.  
  39.  
  40.             if (Math.Round(totalsum,2) <= peshoMoney)
  41.             {
  42.  
  43.  
  44.                 foreach (KeyValuePair<string, decimal> pair in shopingList
  45.                     .OrderByDescending(x => x.Value)
  46.                     .ThenBy(x => x.Key.Length))
  47.                 {
  48.                     Console.WriteLine($"{pair.Key} costs {pair.Value:f2}");
  49.                 }
  50.  
  51.             }
  52.             else
  53.             {
  54.                 Console.WriteLine("Need more money... Just buy banichka");
  55.  
  56.             }
  57.  
  58.  
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment