Advertisement
kasper_k

oop1

Jan 19th, 2023
975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 26.97 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. using System.IO;
  7. using System.Runtime.Serialization.Formatters.Binary;
  8. using System.Runtime.Serialization;
  9. namespace TasksOOP
  10. {
  11.     // 1 task
  12.     /*class Weather: ICloneable
  13.     {
  14.         private string city;
  15.         private int temperature;
  16.         private DateTime data = new DateTime();    
  17.         public string City { get => city;}
  18.         public int Temperature { get => temperature; set => temperature = value; }
  19.         public DateTime Data { get => data; set => data = value; }
  20.         public Weather(string city, int temperature, DateTime dateTime)
  21.         {
  22.             this.city = city;
  23.             Temperature = Converse(temperature);
  24.             Data = dateTime;
  25.         }
  26.         public int Converse(int t)
  27.         {
  28.             return t * (9 / 5) + 32;
  29.         }
  30.         public object Clone()
  31.         {
  32.             //return new Weather(City, Temperature, Data);
  33.             return MemberwiseClone();
  34.         }
  35.     }*/
  36.     // 2 task
  37.     /*class Tourist
  38.     {
  39.         private string name;
  40.         private string direction;
  41.         private int duration;
  42.         //public string Name { get => name; }
  43.         public string Direction { get => direction; set => direction = value; }
  44.         public int Duration { get => duration; set => duration = value; }
  45.         public string Name { get => name; set => name = value; }
  46.  
  47.         public Tourist(string name, string direction)
  48.         {
  49.             this.Name = name;
  50.             Direction = direction;
  51.         }
  52.         public override string ToString()
  53.         {
  54.             return $"Турист: Имя {Name} Направление {Direction} Продолжительность {Duration} дней";
  55.         }
  56.         public static int operator +(Tourist tourist, int val)
  57.         {
  58.             return tourist.Duration + val;
  59.         }
  60.     }*/
  61.     //3 task
  62.     /*class Meropriyatie: IComparable
  63.     {
  64.         private string name;
  65.         private DateTime date;
  66.         private string mesto;
  67.  
  68.         public Meropriyatie(string name, DateTime dateTime, string mesto)
  69.         {
  70.             this.name = name;
  71.             Date = dateTime;
  72.             Mesto = mesto;
  73.         }
  74.  
  75.         public string Name { get => name; }
  76.         public DateTime Date { get => date; set => date = value; }
  77.         public string Mesto { get => mesto; set => mesto = value; }
  78.         public bool Check()
  79.         {
  80.             if (Date >= DateTime.Now) return true;
  81.             else return false;
  82.         }
  83.         public int CompareTo(object o)
  84.         {
  85.             if (o is Meropriyatie os)
  86.             {
  87.                 if (os != null)
  88.                 {
  89.                     return DateTime.Compare(this.date, os.Date);
  90.                 }
  91.                 else throw new ArgumentNullException("Нулевой элемент");
  92.             }
  93.             else
  94.             {
  95.                 throw new ArgumentException("Аргумент неправильного типа!");
  96.             }
  97.         }
  98.     }*/
  99.     //4 task
  100.     /*class Cube
  101.     {
  102.         private int riblength;
  103.  
  104.         public Cube(int rl)
  105.         {
  106.             Riblength = rl;
  107.         }
  108.  
  109.         public int Riblength { get => riblength; set => riblength = value; }
  110.         public int Volume()
  111.         {
  112.             return riblength * riblength * riblength;
  113.         }
  114.         public static int operator +(Cube c1, Cube c2)
  115.         {
  116.             return c1.Volume() + c2.Volume();
  117.         }
  118.         public override string ToString()
  119.         {
  120.             return $"Куб с ребрами = {Riblength} и  объемом = {Volume()}";
  121.         }
  122.     }*/
  123.     //5 task
  124.     /*class Teacher
  125.     {
  126.         private string surname;
  127.         private string kaf;
  128.         private double rating;
  129.         public string Surname { get => surname; set => surname = value; }
  130.         public string Kaf { get => kaf; set => kaf = value; }
  131.         public double Rating { get => rating; set => rating = value; }
  132.         public override string ToString()
  133.         {
  134.             return $"Учитель - {Surname} с кафедры - {Kaf} с рейтингом - {Rating}";
  135.         }
  136.     }
  137.    
  138.      // 5 variant
  139.         [Serializable]
  140.         class Theacher
  141.         {
  142.            
  143.             private string surname;
  144.             private string cathedra;
  145.             private double rating;
  146.  
  147.             public string Surname
  148.             {
  149.                 get => this.surname;
  150.                 set => this.surname = value;
  151.             }
  152.  
  153.             public string Cathedra
  154.             {
  155.                 get => this.cathedra;
  156.                 set=> this.cathedra = value;
  157.             }
  158.  
  159.             public double Rating
  160.             {
  161.                 get => this.rating;
  162.                 set => this.rating = value;
  163.             }
  164.  
  165.             public Theacher()
  166.             {
  167.                 this.surname = "noname";
  168.                 this.cathedra = "Nope";
  169.                 this.rating = 0;
  170.             }
  171.  
  172.             public void WriteOfFiles()
  173.             {
  174.                 string path = "input.txt";
  175.                 using (StreamWriter writer = new StreamWriter(path, true))
  176.                 {
  177.                     writer.WriteLineAsync($"{this.surname}\t{this.cathedra}\t{this.rating}");
  178.                 }
  179.             }
  180.  
  181.  
  182.             public object Clone()
  183.             {
  184.                 using (MemoryStream stream = new MemoryStream())
  185.                 {
  186.                     if (this.GetType().IsSerializable)
  187.                     {
  188.                         BinaryFormatter formatter = new BinaryFormatter();
  189.                         formatter.Serialize(stream, this);
  190.                         stream.Position = 0;
  191.                         return formatter.Deserialize(stream);
  192.                     }
  193.                     return null;
  194.                 }
  195.             }
  196.  
  197.             public override string ToString()
  198.             {
  199.                 return $"{this.surname}\t{this.cathedra}\t{this.rating}";
  200.             }
  201.  
  202.  
  203.         }*/
  204.     //6 task
  205.     /*class Driver
  206.     {
  207.         private string surname;
  208.         private List<String> category;
  209.         private int exper; // стаж
  210.  
  211.         public string Surname
  212.         {
  213.             get => this.surname;
  214.             set => this.surname = value;
  215.         }
  216.         public List<String> Category
  217.         {
  218.             get => this.category;
  219.             set => this.category = value;
  220.         }
  221.         public int Exper
  222.         {
  223.             get => this.exper;
  224.             set => this.exper = value;
  225.         }
  226.  
  227.         public Driver(string surname, List<String> category, int exper)
  228.         {
  229.             this.surname = surname;
  230.             this.category = category;
  231.             this.exper = exper;
  232.         }
  233.  
  234.         public override int GetHashCode()
  235.         {
  236.             return surname.Count() + category.Count() + exper;
  237.         }
  238.  
  239.         public string this[int index]
  240.         {
  241.             get => category[index];
  242.             set => category[index] = value;
  243.         }
  244.  
  245.         public override string ToString()
  246.         {
  247.             return $"Фамилия: {this.surname}\tКатегории: {string.Join(" ", this.category)}\tСтаж: {this.exper}";
  248.         }
  249.  
  250.     }*/
  251.     //7 task
  252.     /*class TK
  253.     {
  254.         private string name;
  255.         private int count;
  256.         public List<string> countries = new List<string>();
  257.         public string Name { get => name; }
  258.         public int Count { get => count; set => count = value; }
  259.         public string this[int index]
  260.         {
  261.             get => countries[index];
  262.         }
  263.         public TK(string name, int count, List<string> vs)
  264.         {
  265.             this.name = name;
  266.             Count = count;
  267.             countries.AddRange(vs);
  268.         }
  269.         public override string ToString()
  270.         {
  271.             return $"Транспортная компания - {Name} с автопарком в {Count} машин, который сотрудничает с такими странами, как {string.Join(", ", countries)}";
  272.         }
  273.     }*/
  274.     //8 task
  275.     /*class Ticket: IComparable
  276.     {
  277.         private string name;
  278.         private string group;
  279.         private DateTime date;
  280.         public string Name
  281.         {
  282.             get => this.name;
  283.         }
  284.         public string Group
  285.         {
  286.             get => this.group;
  287.             set => this.group = value;
  288.         }
  289.         public DateTime Date
  290.         {
  291.             get => this.date;
  292.             set => this.date = value;
  293.         }
  294.  
  295.         public Ticket(string name, string group, DateTime date)
  296.         {
  297.             this.name = name;
  298.             this.group = group;
  299.             this.date = date;
  300.         }
  301.         public void OutputConcert(DateTime dateTime, Ticket[] tickets)
  302.         {
  303.             Console.WriteLine($"Концерты в {dateTime.Day}.{dateTime.Month}.{dateTime.Year}");
  304.             foreach (var item in tickets)
  305.             {
  306.                 if (item.date == dateTime)
  307.                 {
  308.                     Console.WriteLine(item.ToString());
  309.                 }
  310.             }
  311.         }
  312.  
  313.         public override string ToString()
  314.         {
  315.             return $"Название: {this.name}\tГруппа: {this.group}\tДата: {this.date.Day}.{this.date.Month}.{this.date.Year}";
  316.         }
  317.  
  318.         public int CompareTo(object o)
  319.         {
  320.             Ticket tmp = o as Ticket;
  321.             if (tmp != null)
  322.             {
  323.                 return DateTime.Compare(this.date, tmp.date);
  324.             }
  325.             else
  326.                 throw new ArgumentException
  327.                 ("не параметр");
  328.         }
  329.  
  330.     }*/
  331.     //9 task
  332.     /*class Creditka<T>
  333.     {
  334.         private T number;
  335.         private int dolg;
  336.         private DateTime date = DateTime.Now;
  337.  
  338.         public Creditka(T number, int dolg)
  339.         {
  340.             Number = number;
  341.             Dolg = dolg;
  342.         }
  343.         public bool CheckOverdue()
  344.         {
  345.             if (Date > DateTime.Now) return true;
  346.             else return false;
  347.         }
  348.         public static bool operator ==(Creditka<T> c1, Creditka<T> c2)
  349.         {
  350.             if (ReferenceEquals(c1, c2)) return true;
  351.             if ((((object)c1) == null) || (((object)c2) == null)) return false;
  352.             return false;
  353.         }
  354.         static public bool operator !=(Creditka<T> c1, Creditka<T> c2)
  355.         {
  356.             return !(c1 == c2);
  357.         }
  358.         public T Number { get => number; set => number = value; }
  359.         public int Dolg { get => dolg; set => dolg = value; }
  360.         public DateTime Date { get => date; set => date = value; }
  361.         public override string ToString()
  362.         {
  363.             return $"Номер счета: {Number}; Дата задолженности: {Date}";
  364.         }
  365.  
  366.     }*/
  367.     //10 task
  368.     /*class Picture: ICloneable
  369.     {
  370.         private string name;
  371.         private string artist;
  372.         private string museum;
  373.  
  374.         public Picture(string name, string artist, string museum)
  375.         {
  376.             this.name = name;
  377.             this.artist = artist;
  378.             Museum = museum;
  379.         }
  380.  
  381.         public string Name { get => name;}
  382.         public string Artist { get => artist;}
  383.         public string Museum { get => museum; set => museum = value; }
  384.         public override string ToString()
  385.         {
  386.             return $"Картина: {Name}; Художника: {Artist}; Хранится в музее: {Museum}";
  387.         }
  388.         public object Clone()
  389.         {
  390.             return MemberwiseClone();
  391.         }
  392.     }*/
  393.     //26 task
  394.     /*class Company
  395.     {
  396.         private string name;
  397.         private List<string> productions = new List<string>();
  398.  
  399.         public Company(string name)
  400.         {
  401.             this.Name = name;
  402.         }
  403.  
  404.         public string Name { get => name; set => name = value; }
  405.         public List<string> Productions { get => productions; set => productions = value; }
  406.         public void AddProd(params string[] vs)
  407.         {
  408.             productions.AddRange(vs);
  409.         }
  410.         public string this[int index]
  411.         {
  412.             get => productions[index];
  413.         }
  414.     }*/
  415.     //27 task
  416.     /*class Flight: IComparer<Flight>
  417.     {
  418.         private string mesto_otpr;
  419.         private string mesto_pr;
  420.         private DateTime date;
  421.  
  422.         public Flight(string mesto_otpr, string mesto_pr, DateTime date)
  423.         {
  424.             this.Mesto_otpr = mesto_otpr;
  425.             this.Mesto_pr = mesto_pr;
  426.             this.Date = date;
  427.         }
  428.  
  429.         public string Mesto_otpr { get => mesto_otpr; set => mesto_otpr = value; }
  430.         public string Mesto_pr { get => mesto_pr; set => mesto_pr = value; }
  431.         public DateTime Date { get => date; set => date = value; }
  432.         public override string ToString()
  433.         {
  434.             return $"{Mesto_otpr} {Mesto_pr} {Date}";
  435.         }
  436.         public int Compare(Flight f1, Flight f2)
  437.         {
  438.             if (f1.Date > f2.Date) return 1;
  439.             if (f1.Date.Year == f2.Date.Year && f1.Date.Month == f2.Date.Month && f1.Date.Day == f2.Date.Day) return 0;
  440.             else return -1;
  441.             //return
  442.         }*/
  443.     }
  444.  
  445.     class Program
  446.     {
  447.         static void Main(string[] args)
  448.         {
  449.             //1 task
  450.             /*List<Weather> weathers = new List<Weather>();
  451.             Weather weather1 = new Weather("Nurlat", 37, new DateTime(2023, 01, 17));
  452.             Weather weather2 = new Weather("Kazan", 10, new DateTime(2023, 03, 15));
  453.             Weather weather3 = new Weather("Nurlat", -78, new DateTime(2023, 05, 27));
  454.             weathers.Add(weather1);
  455.             weathers.Add(weather2);
  456.             weathers.Add(weather3);
  457.             var linqweathers = weathers.GroupBy(c => c.Data);
  458.             foreach (var weathers1 in linqweathers)
  459.             {
  460.                 foreach (var item in weathers1)
  461.                 {
  462.                     Console.WriteLine($"{item.City} \t {item.Temperature} \t {item.Data}");
  463.                 }
  464.             }*/
  465.             // 2 task
  466.             /*int n = 0;
  467.             Console.Write("Введите кол-во туристов: ");
  468.             n = Int32.Parse(Console.ReadLine());
  469.             Tourist[] tourists = new Tourist[n];
  470.             for (int i = 0; i < tourists.Length; i++)
  471.             {
  472.                 Console.Write($"Введите имя для {i + 1}-го туриста: ");
  473.                 string tname = (string)(Console.ReadLine());
  474.                 Console.Write($"Введите направление для {i + 1}-го туриста: ");
  475.                 string tdirection = (string)(Console.ReadLine());
  476.                 tourists[i] = new Tourist(tname, tdirection);
  477.             }
  478.             for (int i = 0; i < tourists.Length; i++)
  479.             {
  480.                 Console.Write($"Введите продолжительность отдыха для {tourists[i].Name}: ");
  481.                 int d = Int32.Parse(Console.ReadLine());
  482.                 tourists[i].Duration += d;
  483.             }
  484.             var selectedtourusts = tourists.Where(t => t.Duration < 7);
  485.             foreach (var item in selectedtourusts)
  486.             {
  487.                 Console.WriteLine(item.ToString());
  488.             }
  489.             Console.WriteLine($"Минимальная продолжительность отдыха: {tourists.Min(x => x.Duration)}");*/
  490.             // 3 task
  491.             /*Meropriyatie[] meropriyaties = { new Meropriyatie("Самы", new DateTime(2022, 05, 22), "Nurlat"), new Meropriyatie("sdasdas", new DateTime(2022, 06, 11), "Dubai"), new Meropriyatie("dasdada", new DateTime(2022, 08, 11), "Ddsai"), new Meropriyatie("fsdfsdfs", new DateTime(2022, 09, 12), "Kazan") };
  492.             var groupMP = meropriyaties.GroupBy(x => x.Mesto);
  493.             foreach (var item in groupMP)
  494.             {
  495.                 foreach (var elem in item)
  496.                 {
  497.                     Console.WriteLine($"{elem.Name} - {elem.Date} - {elem.Mesto}");
  498.                 }
  499.             }
  500.             var cs = meropriyaties.Where(x => x.Check() == false);
  501.             //meropriyaties
  502.             Console.WriteLine($"Количество прошедних мероприятий {cs.Count()}");*/
  503.             // 4 task
  504.             /*List<Cube> cubes = new List<Cube>() { new Cube(3), new Cube(5), new Cube(4), new Cube(2), new Cube(7) };
  505.             cubes.Add(new Cube(cubes[0] + cubes[1]));
  506.             var selected = cubes.OrderByDescending(x => x.Riblength);
  507.             foreach (var item in selected)
  508.             {
  509.                 Console.WriteLine(item + "\n");
  510.             }
  511.             Console.WriteLine(cubes.Any(x => x.Volume() >= 5));*/
  512.             //5 task
  513.             /*StreamWriter streamWriter = new StreamWriter("C:\\Users\\ПК\\Desktop\\OOP\\output.txt");
  514.             List<Teacher> teachers = new List<Teacher>();
  515.             teachers.Add(new Teacher());
  516.             teachers.Add(new Teacher());
  517.             teachers.Add(new Teacher());
  518.             teachers[0].Surname = "Musin";
  519.             teachers[1].Surname = "Habibi";
  520.             teachers[2].Surname = "Garfiev";
  521.             teachers[0].Kaf = "Kaifa";
  522.             teachers[1].Kaf = "Ne Kaifa";
  523.             teachers[2].Kaf = "Информационная безопасность";
  524.             teachers[0].Rating = 7.0;
  525.             teachers[1].Rating = 3.5;
  526.             teachers[2].Rating = 6.0;
  527.             var ashkerer = teachers.OrderBy(x => x.Rating);
  528.             foreach (var item in ashkerer)
  529.             {
  530.                 Console.WriteLine(item + "\t");
  531.                 streamWriter.WriteLine(item + "\t");
  532.             }
  533.             Console.WriteLine("Имеются ли среди преподавателей сотрудики кафедры Информационная безопасность: " + teachers.Any(x => x.Kaf == "Информационная безопасность"));
  534.             streamWriter.Close();
  535.             List<Theacher> theachers = new List<Theacher>() { new Theacher(), new Theacher() };
  536.             theachers[0].Surname = "Garfiev";
  537.             theachers[1].Surname = "Musin";
  538.             theachers[0].Cathedra = "Высшая математика";
  539.             theachers[1].Cathedra = "Информационная безопасность";
  540.             theachers[0].Rating = 9;
  541.             theachers[1].Rating = 8;
  542.  
  543.  
  544.             var sorted = theachers.OrderByDescending(theacher => theacher.Rating); // linq1
  545.             foreach (var item in sorted)
  546.                 WriteLine(item.ToString());
  547.  
  548.             var teachs = theachers.Where(theacher => theacher.Cathedra == "Информационная безопасность");
  549.             if (teachs.Count() > 0)
  550.                 WriteLine("Имеются преподаватели кафедры Информационная безопасность");
  551.             else
  552.                 WriteLine("Отсутствуют преподаватели кафедры Информационная безопасность");
  553.  
  554.             Theacher theacher = theachers[0].Clone() as Theacher;
  555.             WriteLine(theacher.ToString());*/
  556.             // 6 task
  557.             /*List<Driver> drivers = new List<Driver>() { new Driver("Musin", "A", 12), new Driver("Garfiev", "B", 2), new Driver("Razjevalov", "C", 3), new Driver("Valiev", "B", 22) };
  558.             var orderedbyexp = drivers.OrderBy(x => x.Experience);
  559.             for (int i = 0; i < orderedbyexp.Count(); i++)
  560.             {
  561.                 string s = drivers[i][i];
  562.                 Console.WriteLine(orderedbyexp + "\t" + s);
  563.             }
  564.             foreach (var item in orderedbyexp)
  565.             {
  566.                 for (int i = 0; i < drivers.Count; i++)
  567.                 {
  568.                     Console.WriteLine(item + "\t" + item[i]);
  569.                 }
  570.                
  571.             }
  572.            
  573.             List<String> list1 = new List<String>() {"A", "B", "E"};
  574.             List<String> list2 = new List<String>() { "B", "C", "D" };
  575.  
  576.             List<Driver> drivers = new List<Driver>() { new Driver("Garfiev", list1, 1), new Driver("Musin",list2, 2) };
  577.             WriteLine("Первая категория Ильсафа: " + drivers[1].Category[0]);
  578.  
  579.             var sorted = drivers.OrderByDescending(driver => driver.Exper); // linq1
  580.             foreach (var item in sorted)
  581.                 WriteLine(item.ToString());
  582.  
  583.             var filter = drivers.Where(driver => driver.Category.Any(x => x == "E")); // linq2
  584.             foreach (var item in filter)
  585.                 WriteLine(item.ToString());*/
  586.             //7 task
  587.             /*List<TK> tKs = new List<TK>() { new TK("dada", 6, new List<string>(){"bdadda", "dadad", "dasdasdasdsad", "nurlat", "sdsadadasdsa", "OAE"}), new TK("dada", 5, new List<string>() { "bdsa", "dadadasdasdd", "dasda12sdasdsad", "dubai", "aseqs"}), new TK("aedd", 4, new List<string>() { "aoas", "fvs", "sdad", "nurlat" }), };
  588.             var svs = tKs.Max(x => x.countries.Count);
  589.             Console.WriteLine($"Max: {svs}");
  590.             var selected = tKs.Where(x => x.countries.Count == svs);
  591.             foreach (var item in selected)
  592.             {
  593.                 Console.WriteLine(item + "\t");
  594.             }
  595.             Console.WriteLine("\nSorted by Name");
  596.             var sorted = tKs.OrderBy(x => x.Name);
  597.             foreach (var item in sorted)
  598.             {
  599.                 Console.WriteLine(item + "\t");
  600.             }*/
  601.             // 9 task
  602.             /*List<Creditka<int>> creditkas = new List<Creditka<int>>() { new Creditka<int>(1111, 100000), new Creditka<int>(1112, 10000), new Creditka<int>(1113, 20000), new Creditka<int>(1114, 200000), new Creditka<int>(1115, 14000) };
  603.             creditkas[0].Date = new DateTime(2022, 12, 12);
  604.             creditkas[1].Date = new DateTime(2022, 11, 22);
  605.             creditkas[3].Date = new DateTime(2023, 05, 26);
  606.             Console.WriteLine(creditkas[0] == creditkas[1]);
  607.             Console.WriteLine(creditkas[0] != creditkas[1]);
  608.             Console.WriteLine($"Количество карт с просроченной задолженностью: {creditkas.Count(x => x.CheckOverdue() == true)}");
  609.             var l2 = creditkas.OrderByDescending(x => x.Date);
  610.             Console.WriteLine("Отфильтровать кредитные карты по задолженности в порядке убывания:");
  611.             foreach (var item in l2)
  612.             {
  613.                 Console.WriteLine(item + "\t");
  614.             }*/
  615.             //10 task
  616.             /*List<Picture> pictures = new List<Picture>() { new Picture("dasdasdsa", "Шишкин", "gallert"), new Picture("annbc", "Мусин", "kazanskii museum"), new Picture("салам", "Шишкин", "gallert"), new Picture("утро в сосновом бору", "Гарфиев", "kazanskii museum")};
  617.             var clone1 = pictures[0].Clone();
  618.             Console.WriteLine(clone1);
  619.             Console.WriteLine();
  620.             var pictures1 = pictures.GroupBy(x => x.Museum);
  621.             foreach (var item in pictures1)
  622.             {
  623.                 foreach (var elem in item)
  624.                 {
  625.                     Console.WriteLine(elem.ToString());
  626.                 }
  627.             }
  628.             Console.WriteLine();
  629.             Console.WriteLine($"Сколько картин написаны Шишкиным: {pictures.Count(x => x.Artist == "Шишкин")}");*/
  630.             //26 task
  631.             /*Company[] companies = new Company[4] { new Company("Danone"), new Company("Logitech"), new Company("Nike"), new Company("Adidas")};
  632.             companies[0].AddProd("dasdad", "kakaka", "qw12o1", "da31l1");
  633.             companies[1].AddProd("ПО", "клавиатура", "naushniki", "kovrik");
  634.             companies[2].AddProd("krossovki", "kedi", "толстовки", "noski");
  635.             companies[3].AddProd("худи", "свитер", "джемпер", "обцыь");
  636.             Console.WriteLine(companies[0].Productions[0]);
  637.             Console.WriteLine();
  638.             var pp = companies.Select(p => new
  639.             {
  640.                 FName = p.Name,
  641.                 PCount = p.Productions.Count
  642.             });
  643.             foreach (var item in pp)
  644.             {
  645.                 Console.WriteLine($"{item.FName}  {item.PCount}");
  646.             }
  647.             bool check = false;
  648.             foreach (var item in companies)
  649.             {
  650.                 for (int i = 0; i < item.Productions.Count; i++)
  651.                 {                    
  652.                     check = companies.Any(c => c.Productions[i] == "клавиатура");
  653.                     if (check) break;
  654.                 }
  655.                 if (check) break;
  656.             }
  657.             if (check) Console.WriteLine("Есть предприятие, которое производит клавиатуры");
  658.             else Console.WriteLine("Нет предприятия, которое производит клавиатуры");
  659.             //Console.WriteLine(companies.Any(c => c.Productions == "клавиатура"));*/
  660.             //8 task
  661.             /*Ticket[] tickets = { new Ticket("Nickelodion", "OneDir", new DateTime(2023, 1, 20)), new Ticket("Muzloft", "OneDir", new DateTime(2023, 1, 19)) };
  662.             var filter = tickets.Where(ticket => ticket.Date.Day == DateTime.Now.Day && ticket.Date.Month == DateTime.Now.Month && ticket.Date.Year == DateTime.Now.Year); // linq2
  663.             //var filter = tickets.Where(t => t.Date == DateTime.Now);
  664.             //Console.WriteLine(DateTime.Now);
  665.             foreach (var item in filter)
  666.                 Console.WriteLine(item.ToString());
  667.             //linq1
  668.             var grouping = tickets.GroupBy(ticket => ticket.Group); // linq1
  669.             foreach (IGrouping<string, Ticket> ticket in grouping)
  670.             {
  671.                 Console.WriteLine("Группа: " + ticket.Key);
  672.                 foreach (var q in ticket)
  673.                 {
  674.                     Console.WriteLine($"Название: {q.Name}\t Дата: {q.Date.Day}.{q.Date.Month}.{q.Date.Year}");
  675.                 }
  676.                 Console.WriteLine();
  677.             }// linq2
  678.             if (tickets[0].CompareTo(tickets[1]) > 0) Console.WriteLine("Концерт еще не прошел");*/
  679.             //27 task
  680.             /*List<Flight> flights = new List<Flight>() { new Flight("Казань", "Дубай", new DateTime(2023, 01, 26)), new Flight("Москва", "Сингапур", new DateTime(2023, 02, 12)), new Flight("Москва", "Таиланд", new DateTime(2023, 01, 24)), new Flight("Дубай", "Москва", new DateTime(2023, 02, 26)) };
  681.             flights.Sort(flights[2]);
  682.             foreach (var item in flights)
  683.             {
  684.                 Console.WriteLine(item + "\t");
  685.             }
  686.             Console.WriteLine();
  687.             var s = flights.Where(x => x.Mesto_pr == "Москва");
  688.             foreach (var item in s)
  689.             {
  690.                 Console.WriteLine(item + "\t");
  691.             }*/
  692.             Console.ReadKey();
  693.         }
  694.     }
  695. }
  696.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement