zhivko1985

Andrey and billiard

Apr 19th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.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 _7.Andrey_and_billiard
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             var productPrice = new Dictionary<string,double>();
  15.             for (int i = 0; i < n; i++)
  16.             {
  17.                 var currentText = Console.ReadLine().Split('-').ToArray();
  18.                 productPrice[currentText[0]] = double.Parse(currentText[1]);
  19.             }
  20.             var listCustomers = new List<Customer>();
  21.             string nameProductQnty = Console.ReadLine();
  22.  
  23.             while (!nameProductQnty.Equals("end of clients"))
  24.             {
  25.                 var takeNameArr = nameProductQnty.Split('-').ToArray();
  26.                 var takeproductQntyArr = takeNameArr[1].Split(',').ToArray();
  27.                 var cuurentCustomer = new Customer();
  28.                 cuurentCustomer.name = takeNameArr[0];
  29.                 cuurentCustomer.productQnty = new Dictionary<string, double>();
  30.                 cuurentCustomer.productQnty[takeproductQntyArr[0]] = double.Parse(takeproductQntyArr[1]);
  31.                 listCustomers.Add(cuurentCustomer);
  32.                 nameProductQnty = Console.ReadLine();
  33.             }
  34.             //---------------------------------------------------------------------------------------------
  35.             var listBills = new List<double>();
  36.             foreach (var item  in listCustomers.OrderBy(x=>x.name))
  37.             {
  38.                 foreach (var product in item.productQnty.Keys)
  39.                 {
  40.  
  41.                     if (productPrice.Keys.Contains(product))
  42.                     {
  43.                         Console.WriteLine(item.name);
  44.                         Console.WriteLine($"-- {product} - {item.productQnty[product]}");
  45.                         Console.WriteLine("Bill: {0:f2}", item.productQnty[product]*productPrice[product]);
  46.                         listBills.Add(item.productQnty[product] * productPrice[product]);
  47.                     }
  48.                 }
  49.             }
  50.             var sumListBills = listBills.Sum();
  51.             Console.WriteLine("Total bill: {0:f2}",sumListBills);
  52.             //---------------------------------------------------------------------------------------------
  53.         }
  54.     }
  55.     public class Customer
  56.     {
  57.         public string name { get; set; }
  58.         public Dictionary<string, double> productQnty { get; set; }
  59.  
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment