Advertisement
YavorJS

Sales Report

Oct 11th, 2016
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 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.  
  8. class SalesReportGenerator
  9. {
  10. static void Main(string[] args)
  11. {
  12. int n = int.Parse(Console.ReadLine());
  13.  
  14. Sale[] sales = new Sale[n];
  15. for (int i = 0; i < n; i++)
  16. {
  17. sales[i] = readSale();
  18. }
  19. SortedDictionary<string, decimal> salesByTown = new SortedDictionary<string, decimal>();
  20. for (int i = 0; i < n; i++)
  21. {
  22. if (!salesByTown.ContainsKey(sales[i].town))
  23. {
  24. salesByTown.Add(sales[i].town, 0);
  25. }
  26.  
  27. salesByTown[sales[i].town] += sales[i].price * sales[i].quantity;
  28. }
  29. foreach (var town in salesByTown)
  30. {
  31. Console.WriteLine($"{town.Key} -> {town.Value:f2}");
  32. }
  33. }
  34.  
  35. private static Sale readSale()
  36. {
  37.  
  38. string[] sale = Console.ReadLine().Split().ToArray();
  39. Sale singleSale = new Sale() { town = sale[0], product = sale[1], price = decimal.Parse(sale[2]), quantity = decimal.Parse(sale[3]) };
  40. return singleSale;
  41. }
  42. }
  43.  
  44. class Sale
  45. {
  46. public string town { get; set; }
  47. public string product { get; set; }
  48. public decimal price { get; set; }
  49. public decimal quantity { get; set; }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement