Aliendreamer

most valuale customer

Jul 19th, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.95 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 _04LinqMoreExcercisesMostValueableCustomer
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             string input =Console.ReadLine();
  15.  
  16.             Dictionary<string, decimal> products = new Dictionary<string, decimal>();
  17.  
  18.             Dictionary<string, List<string>> Byers = new Dictionary<string, List<string>>();
  19.  
  20.  
  21.             while(input!="Shop is open")
  22.             {
  23.                
  24.                 string[] inputTokens = input.Split(' ').ToArray();
  25.                 string product = inputTokens[0];
  26.                 decimal price = decimal.Parse(inputTokens[1]);
  27.  
  28.                
  29.                 products.Add(product,price);
  30.  
  31.                 input = Console.ReadLine();
  32.  
  33.             }
  34.  
  35.             // half input done
  36.             //  Console.WriteLine("halfway input done");
  37.  
  38.  
  39.             input = Console.ReadLine();
  40.  
  41.             while (input!="Print")
  42.             {
  43.  
  44.                 if (input != "Discount")
  45.                 {
  46.                     string[] boughtProducts = input.Split(new string[]{": ",", "},StringSplitOptions.RemoveEmptyEntries).ToArray();
  47.  
  48.                     string boughtItem = String.Empty;
  49.                     string Name = boughtProducts[0];
  50.                     Byers.Add(Name, new List<string>());
  51.                     for (int i = 1; i < boughtProducts.Length; i++)
  52.                     {
  53.                         boughtItem = boughtProducts[i];
  54.                         Byers[Name].Add(boughtItem);
  55.                     }
  56.  
  57.                 }
  58.                 else
  59.  
  60.                 {
  61.                   List<KeyValuePair<string,decimal>>topthree=  products.OrderByDescending(x => x.Value).Take(3).ToList();
  62.  
  63.                     foreach (KeyValuePair<string,decimal> pair in topthree)
  64.                     {
  65.                         string name = pair.Key;
  66.                         decimal sum= pair.Value;
  67.  
  68.                         products[name] =sum -(sum* 0.10M);
  69.                     }
  70.  
  71.                 }
  72.  
  73.  
  74.                 input = Console.ReadLine();
  75.             }
  76.  
  77.             // logic done left to do output
  78.             // Console.WriteLine("discount done");
  79.  
  80.             Dictionary<string, decimal> bestbyer = new Dictionary<string, decimal>();
  81.  
  82.             string bestOne =string.Empty;
  83.          
  84.  
  85.             foreach (var pair in Byers)
  86.             {
  87.                 decimal total = 0;
  88.                 bestOne = pair.Key;
  89.                 List<string> boughtProducts = pair.Value;
  90.  
  91.                 foreach (string product in boughtProducts)
  92.                 {
  93.                    
  94.                  total += products[product];
  95.                                  
  96.                 }
  97.  
  98.                 bestbyer.Add(bestOne, total);
  99.             }
  100.  
  101.             // fucking calculations done stupid split options and white spaces!
  102.             // Console.WriteLine("done?!?");
  103.             foreach (KeyValuePair<string,decimal> pair in bestbyer.OrderByDescending(x=>x.Value).Take(1))
  104.             {
  105.                 string name = pair.Key;
  106.                 Console.WriteLine($"Biggest spender: {pair.Key}");
  107.                 Console.WriteLine("^Products bought:");
  108.  
  109.                 List<string> items = Byers[name].Distinct().ToList()
  110.  
  111.                 Dictionary<string, decimal> itemsFinal = new Dictionary<string, decimal>();
  112.  
  113.                 for(int k=0;k<items.Count;k++)
  114.                 {
  115.                 itemsFinal[items[k]]=products[items[k]];
  116.                 }
  117.                                  
  118.                foreach (var product in itemsFinal.OrderByDescending(x=>x.Value))
  119.                {
  120.                Console.WriteLine($"^^^{product.Key}: {product.Value:f2}");
  121.                }
  122.                Console.WriteLine("Total: {0:f2}",pair.Value);
  123.                
  124.             }
  125.           // fucking done nightmare!
  126.  
  127.  
  128.  
  129.  
  130.         }
  131.     }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment