Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace _07._Sales_Report__second_solution_
- {
- class Sale
- {
- public string Town { get; set; }
- public string Product { get; set; }
- public decimal Price { get; set; }
- public decimal Quantity { get; set; }
- public Sale(string Town, string Product, decimal Price, decimal Quantity)
- {
- this.Town = Town;
- this.Product = Product;
- this.Price = Price;
- this.Quantity = Quantity;
- }
- public decimal Multiply()
- {
- return Price * Quantity;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- List<Sale> sales = new List<Sale>();
- SortedDictionary<string, decimal> totalSalesByTown = new SortedDictionary<string, decimal>();
- for (int i = 0; i < n; i++)
- {
- string[] data = Console.ReadLine().Split();
- string town = data[0];
- string product = data[1];
- decimal price = decimal.Parse(data[2]);
- decimal quantity = decimal.Parse(data[3]);
- Sale sale = new Sale(town, product, price, quantity);
- sales.Add(sale);
- }
- foreach (var sale in sales)
- {
- if (!totalSalesByTown.ContainsKey(sale.Town))
- {
- totalSalesByTown.Add(sale.Town, sale.Multiply());
- }
- else
- {
- totalSalesByTown[sale.Town] += sale.Multiply();
- }
- }
- foreach (var town in totalSalesByTown)
- {
- Console.WriteLine($"{town.Key} -> {town.Value:f2}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement