dave_kamenenko

laggage

Mar 19th, 2022 (edited)
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace luggage
  6. {
  7.    
  8.     public class Laggage_info
  9.     {
  10.  
  11.         public string name;
  12.         public static int count_all;
  13.         public static double weight_all, weight_medium;
  14.         public static Dictionary<string, double> information =new Dictionary<string, double>();
  15.         public static Dictionary<string, double> information_new = new Dictionary<string, double>();
  16.         public Laggage_info(string name, int count, double weight)
  17.         {
  18.             information.Add($"{name} has  {count} things with a total {weight} weight, average baggage weight", weight/count);
  19.            
  20.            
  21.         }
  22.         public Laggage_info(string name, int count, double[] weight)
  23.         {
  24.             string str = "";
  25.             for (int i = 0; i < weight.Length; i++)
  26.             {
  27.                 str += $"{weight[i]};";
  28.                 weight_all += weight[i];
  29.             }
  30.             str = str.Remove((str.Length - 1));
  31.             information.Add($"{name} has  {count} things ({str}) with a total {weight_all} weight, average baggage weight", weight_all / count);
  32.         }
  33.  
  34.  
  35.  
  36.         public void Print()
  37.         {
  38.             weight_medium = weight_all / count_all;
  39.             //Console.WriteLine($"{weight_all} - {count_all} - {weight_medium}");
  40.             var list = information.Keys.ToList();
  41.  
  42.  
  43.             foreach (var key in list)
  44.             {
  45.                 if ((information[key] + 300) == weight_medium || (information[key] - 300) == weight_medium) information_new.Add(key, information[key]);
  46.  
  47.                 Console.WriteLine("{0}: {1}", key, information[key]);
  48.             }
  49.  
  50.             Console.WriteLine("\n\nBaggage whose average weight differs by 300 grams from the total weight of the items");
  51.             var list_1 = information_new.Keys.ToList();
  52.  
  53.             if (information_new.Count == 0) Console.WriteLine("Empty");
  54.             else
  55.             {
  56.                 foreach (var key in list_1)
  57.                 {
  58.                     Console.WriteLine("{0}: {1}", key, information_new[key]);
  59.                 }
  60.             }
  61.            
  62.            
  63.         }
  64.         ~Laggage_info() { }
  65.     }
  66.    
  67.  
  68.  
  69.  
  70.     class Program
  71.     {
  72.        
  73.  
  74.         static void Main(string[] args)
  75.         {
  76.      
  77.             Laggage_info info = new("Dmitry Ivanko", 10, 23.2);
  78.             Laggage_info info_1 = new ("Ann Vasilenko", 10, 35.6);
  79.             Laggage_info info_2 = new ("Yan Gordienko", 12, 75);
  80.             Laggage_info info_3 = new ("Ameli Lisova", 3, 29.8);
  81.             Laggage_info info_4 = new ("Ivan Durnev", 1, 34);
  82.             Laggage_info info_5 = new ("Hrystyna Dnova", 2, 21.08);
  83.             Laggage_info info_6 = new ("Alexey Ivleev", 3, 120.2);
  84.             Laggage_info info_7 = new ("Dina Saeva", 15, 45.5);
  85.             Laggage_info info_8 = new ("Arina Zelensky", 10, 88.09);
  86.             Laggage_info info_9 = new ("Ivan Holoborodko", 1, 43);
  87.             Laggage_info info_10 = new ("Anastasya Sycheva", 6, 53.2);
  88.             double[] Array = { 3.3, 2.2, 1.1, 7.7, 8.8, 9,9 };
  89.             Laggage_info info_11 = new("Anastasya Sycheva", 6, Array);
  90.             info.Print();
  91.            
  92.         }
  93.     }
  94. }
  95.  
Add Comment
Please, Sign In to add comment