Advertisement
Guest User

7. Andrey and billiard

a guest
Oct 12th, 2016
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.63 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 Customer
  10.     {
  11.         public string Name { get; set; }
  12.         public Dictionary<string,int> ShopList{ get; set; }      
  13.         public double Bil { get; set; }
  14.        
  15.     }  
  16.     class Program
  17.     {
  18.         static void Main()
  19.         {
  20.            
  21.             Dictionary<string, double> menu = new Dictionary<string, double>();
  22.             int numberOfItems = int.Parse(Console.ReadLine());
  23.             for (int i = 0; i < numberOfItems; i++)
  24.             {
  25.                 string[] input = Console.ReadLine().Split('-');
  26.                 if (!menu.ContainsKey(input[0]))
  27.                 {
  28.                     menu.Add(input[0], double.Parse(input[1]));
  29.                 }
  30.                 else
  31.                 {
  32.                     menu[input[0]] = double.Parse(input[1]);
  33.                 }
  34.                
  35.             }
  36.             List<Customer> allCustomers = new List<Customer>();          
  37.             while(true)
  38.             {
  39.                 string info = Console.ReadLine();
  40.                 if (info=="end of clients")
  41.                 {
  42.                     break;
  43.                 }
  44.                 string[] clientInfo = info.Split('-',',');
  45.                 if (menu.ContainsKey(clientInfo[1]))
  46.                 {
  47.                     Customer client = new Customer();
  48.                     client.ShopList = new Dictionary<string, int>();
  49.                     client.Name = clientInfo[0];
  50.                     client.ShopList.Add(clientInfo[1],int.Parse(clientInfo[2]));
  51.                     client.Bil = menu[clientInfo[1]] * int.Parse(clientInfo[2]);
  52.                     allCustomers.Add (client);                  
  53.                 }              
  54.             }
  55.             double sum = 0;
  56.             var ordered = allCustomers
  57.                             .OrderBy(x => x.Name)
  58.                             .ThenBy(x => x.Bil)
  59.                             .ToList();
  60.             foreach (var customer in ordered)
  61.             {
  62.                 Console.WriteLine(customer.Name);
  63.                 foreach (KeyValuePair<string, int> item in customer.ShopList)
  64.                 {
  65.                     Console.WriteLine($"-- {item.Key} - {item.Value}");
  66.                 }
  67.                 Console.WriteLine("Bill: {0:f2}", customer.Bil);
  68.                 sum += customer.Bil;
  69.  
  70.             }
  71.        
  72.             Console.WriteLine("Total bill: {0:f2}",sum);
  73.  
  74.         }                                                                    
  75.        }      
  76.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement