Advertisement
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 _7.Andrey_and_billiard
- {
- class Customer
- {
- public string Name { get; set; }
- public Dictionary<string,int> ShopList{ get; set; }
- public double Bil { get; set; }
- }
- class Program
- {
- static void Main()
- {
- Dictionary<string, double> menu = new Dictionary<string, double>();
- int numberOfItems = int.Parse(Console.ReadLine());
- for (int i = 0; i < numberOfItems; i++)
- {
- string[] input = Console.ReadLine().Split('-');
- if (!menu.ContainsKey(input[0]))
- {
- menu.Add(input[0], double.Parse(input[1]));
- }
- else
- {
- menu[input[0]] = double.Parse(input[1]);
- }
- }
- List<Customer> allCustomers = new List<Customer>();
- while(true)
- {
- string info = Console.ReadLine();
- if (info=="end of clients")
- {
- break;
- }
- string[] clientInfo = info.Split('-',',');
- if (menu.ContainsKey(clientInfo[1]))
- {
- Customer client = new Customer();
- client.ShopList = new Dictionary<string, int>();
- client.Name = clientInfo[0];
- client.ShopList.Add(clientInfo[1],int.Parse(clientInfo[2]));
- client.Bil = menu[clientInfo[1]] * int.Parse(clientInfo[2]);
- allCustomers.Add (client);
- }
- }
- double sum = 0;
- var ordered = allCustomers
- .OrderBy(x => x.Name)
- .ThenBy(x => x.Bil)
- .ToList();
- foreach (var customer in ordered)
- {
- Console.WriteLine(customer.Name);
- foreach (KeyValuePair<string, int> item in customer.ShopList)
- {
- Console.WriteLine($"-- {item.Key} - {item.Value}");
- }
- Console.WriteLine("Bill: {0:f2}", customer.Bil);
- sum += customer.Bil;
- }
- Console.WriteLine("Total bill: {0:f2}",sum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement