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.IO;
- namespace ConsoleApplication2
- {
- struct SBagage: IComparable
- {
- public string name;
- public int count, weight;
- public SBagage (string name, int count, int weight)
- {
- this.name = name;
- this.count = count;
- this.weight = weight;
- }
- public void Show()
- {
- Console.WriteLine("{0}; количество вещей: {1}; вес: {2}", name, count, weight);
- }
- public double Average ()
- {
- return weight / count;
- }
- public int CompareTo(object obj)
- {
- SBagage person = (SBagage) obj;
- return this.count.CompareTo(person.count);
- }
- /*public int CompareTo(int n_weight)
- {
- if (this.Average() == n_weight)
- return 0; else
- if (this.Average() < n_weight)
- return -1; else
- return 1;
- }
- public int CompareTo(SBagage x)
- {
- if (this.count == x.count)
- return 0; else
- if (this.count < x.count)
- return -1; else
- return 1;
- }*/
- }
- class Program
- {
- static void Sort(ref SBagage[] array)
- {
- for (int i = 0; i < array.Length; i++)
- for (int j = i+1; j < array.Length; j++)
- if (array[j].CompareTo(array[i]) >= 0)
- {
- SBagage tmp = new SBagage();
- tmp = array[i];
- array[i] = array[j];
- array[j] = tmp;
- }
- }
- static void Main(string[] args)
- {
- using (StreamReader input = new StreamReader("e:/practice/input.txt", Encoding.GetEncoding(1251)))
- {
- int n = int.Parse(input.ReadLine());
- SBagage [] array = new SBagage[n];
- for (int i = 0; i < n; i++)
- {
- string [] tmp = input.ReadLine().Split(',');
- array[i].name = tmp[0];
- array[i].count = int.Parse(tmp[1]);
- array[i].weight = int.Parse(tmp[2]);
- }
- using (StreamWriter output = new StreamWriter("e:/practice/output.txt", false))
- {
- //Array.Sort(array);
- Sort(ref array);
- Console.WriteLine("Введите вес: ");
- float nor = float.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- if (array[i].Average() > nor)
- output.WriteLine("{0} — {1} — {2}кг", array[i].name, array[i].count, array[i].weight);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement