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 _04LinqMoreExcercisesMostValueableCustomer
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input =Console.ReadLine();
- Dictionary<string, decimal> products = new Dictionary<string, decimal>();
- Dictionary<string, List<string>> Byers = new Dictionary<string, List<string>>();
- while(input!="Shop is open")
- {
- string[] inputTokens = input.Split(' ').ToArray();
- string product = inputTokens[0];
- decimal price = decimal.Parse(inputTokens[1]);
- products.Add(product,price);
- input = Console.ReadLine();
- }
- // half input done
- // Console.WriteLine("halfway input done");
- input = Console.ReadLine();
- while (input!="Print")
- {
- if (input != "Discount")
- {
- string[] boughtProducts = input.Split(new string[]{": ",", "},StringSplitOptions.RemoveEmptyEntries).ToArray();
- string boughtItem = String.Empty;
- string Name = boughtProducts[0];
- Byers.Add(Name, new List<string>());
- for (int i = 1; i < boughtProducts.Length; i++)
- {
- boughtItem = boughtProducts[i];
- Byers[Name].Add(boughtItem);
- }
- }
- else
- {
- List<KeyValuePair<string,decimal>>topthree= products.OrderByDescending(x => x.Value).Take(3).ToList();
- foreach (KeyValuePair<string,decimal> pair in topthree)
- {
- string name = pair.Key;
- decimal sum= pair.Value;
- products[name] =sum -(sum* 0.10M);
- }
- }
- input = Console.ReadLine();
- }
- // logic done left to do output
- // Console.WriteLine("discount done");
- Dictionary<string, decimal> bestbyer = new Dictionary<string, decimal>();
- string bestOne =string.Empty;
- foreach (var pair in Byers)
- {
- decimal total = 0;
- bestOne = pair.Key;
- List<string> boughtProducts = pair.Value;
- foreach (string product in boughtProducts)
- {
- total += products[product];
- }
- bestbyer.Add(bestOne, total);
- }
- // fucking calculations done stupid split options and white spaces!
- // Console.WriteLine("done?!?");
- foreach (KeyValuePair<string,decimal> pair in bestbyer.OrderByDescending(x=>x.Value).Take(1))
- {
- string name = pair.Key;
- Console.WriteLine($"Biggest spender: {pair.Key}");
- Console.WriteLine("^Products bought:");
- List<string> items = Byers[name].Distinct().ToList()
- Dictionary<string, decimal> itemsFinal = new Dictionary<string, decimal>();
- for(int k=0;k<items.Count;k++)
- {
- itemsFinal[items[k]]=products[items[k]];
- }
- foreach (var product in itemsFinal.OrderByDescending(x=>x.Value))
- {
- Console.WriteLine($"^^^{product.Key}: {product.Value:f2}");
- }
- Console.WriteLine("Total: {0:f2}",pair.Value);
- }
- // fucking done nightmare!
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment