Advertisement
Infiniti_Inter

16-II (S)

Dec 9th, 2019
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 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.Text.RegularExpressions;
  7. using System.IO;
  8.  
  9.  
  10. class MainClass
  11. {
  12.  
  13.     struct BagageList : IComparable
  14.     {
  15.         string Name;
  16.         int CountOfThings;
  17.         double Weight;
  18.  
  19.         public BagageList(string Name, int CountOfThings, double Weight){
  20.             this.Name = Name;
  21.             this.CountOfThings = CountOfThings;
  22.             this.Weight = Weight;
  23.            
  24.         }
  25.  
  26.         public bool checkBagage(double weight)
  27.         {
  28.             if (Weight / CountOfThings > weight)
  29.                 return true;
  30.             else
  31.                 return false;
  32.         }
  33.         public int CompareTo(object obj)
  34.         {
  35.             BagageList person = (BagageList)obj;
  36.             return this.CountOfThings.CompareTo(person.CountOfThings);
  37.         }
  38.  
  39.         public override string ToString()
  40.         {
  41.             return String.Format("Фамилия: {0}; количество вещей в багаже: {1}; вес багажа: {2}\n", Name, CountOfThings, Weight);
  42.         }
  43.  
  44.  
  45.  
  46.  
  47.     }
  48.  
  49.     public static void Main(string[] args)
  50.     {
  51.  
  52.  
  53.  
  54.         using (StreamWriter fileOut = new StreamWriter(@"C:/Users/karpenkoos/desktop/output.txt"))
  55.         {
  56.             using (StreamReader fileIn = new StreamReader(@"C:/Users/karpenkoos/desktop/input.txt"))
  57.             {
  58.  
  59.                 var a = fileIn.ReadToEnd().Split('\n');
  60.                 BagageList[] c = new BagageList[a.Length];
  61.                 for (int i = 0; i < a.Length; ++i)
  62.                 {
  63.                     string[] temp = a[i].Split(' ');
  64.                     c[i] = new BagageList(temp[0], int.Parse(temp[1]), double.Parse(temp[2]));
  65.                 }
  66.  
  67.                 double weight = 6;
  68.  
  69.                 var answer = c.Where(x => x.checkBagage(weight)).OrderBy(x => x);
  70.                 foreach (var v in answer)
  71.                     fileOut.WriteLine(v);
  72.             }
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement