Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 197 additions & 0 deletions Purple_1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
using System;
using System.Linq;

namespace Lab_7
{
public class Purple_1
{
public class Judge
{
private string _name;
private int[] _marks;
private int _counter;
public string Name => _name;

public Judge(string name, int[] marks)
{
_name = name;
_marks = marks != null ? marks.ToArray() : new int[0];
_counter = 0;
}

public int CreateMark()
{
if (_marks == null || _marks.Length == 0) return 0;
return _marks[_counter++ % _marks.Length];
}

public void Print()
{
Console.Write($"{_name,7} - ");
foreach (int x in _marks) Console.Write($"{x} ");
Console.WriteLine();
}
}

public class Participant
{
private string _name;
private string _surname;
private double[] _coefs;
private int[,] _marks;
private int _jump;

public string Name => _name;
public string Surname => _surname;

public Participant(string name, string surname)
{
_name = name;
_surname = surname;
_coefs = Enumerable.Repeat(2.5, 4).ToArray();
_marks = new int[4, 7];
_jump = 0;
}

public double[] Coefs
{
get
{
if (_coefs == null) return null;
var clone = new double[_coefs.Length];
Array.Copy(_coefs, clone, _coefs.Length);
return clone;
}
}

public int[,] Marks
{
get
{
if (_marks == null) return null;
var copy = new int[_marks.GetLength(0), _marks.GetLength(1)];
Array.Copy(_marks, copy, _marks.Length);
return copy;
}
}

public void Jump(int[] marks)
{
if (marks == null || _marks == null || _jump > 3 || marks.Length != 7) return;
for (int i = 0; i < 7; i++)
{
_marks[_jump, i] = marks[i];
}
_jump++;
}

public void SetCriterias(double[] coefs)
{
if (_coefs == null || coefs == null || _coefs.Length != 4 || coefs.Length != 4) return;
for (int i = 0; i < 4; i++)
_coefs[i] = coefs[i];
}

public static void Sort(Participant[] array)
{
if (array == null) return;
double[] scores = array.Select(p => p.TotalScore).ToArray();
for (int i = 1, j = 2; i < array.Length;)
{
if (i == 0 || scores[i] < scores[i - 1])
{
i = j;
j++;
}
else
{
(scores[i], scores[i - 1]) = (scores[i - 1], scores[i]);
(array[i], array[i - 1]) = (array[i - 1], array[i]);
i--;
}
}
}

public void Print()
{
Console.WriteLine($"{Name} {Surname} {TotalScore}");
}

public double TotalScore
{
get
{
if (_marks == null || _coefs == null) return 0;
double total = 0;
for (int i = 0; i < 4; i++)
{
double sum = 0;
int min = 0, max = 0;
for (int j = 0; j < 7; j++)
{
if (_marks[i, j] > _marks[i, max]) max = j;
if (_marks[i, j] < _marks[i, min]) min = j;
}
for (int j = 0; j < 7; j++)
{
if (j != min && j != max) sum += _marks[i, j];
}
total += sum * _coefs[i];
}
return total;
}
}
}

public class Competition
{
private Judge[] _judges;
private Participant[] _participants;

public Judge[] Judges => _judges;
public Participant[] Participants => _participants;

public Competition(Judge[] judges)
{
_judges = judges;
_participants = Array.Empty<Participant>();
}

public void Evaluate(Participant jumper)
{
if (_judges == null || jumper == null) return;
int[] marks = new int[_judges.Length];
for (int i = 0; i < _judges.Length; i++)
{
marks[i] = _judges[i].CreateMark();
}
jumper.Jump(marks);
}

public void Add(Participant jumper)
{
if (jumper == null) return;
Evaluate(jumper);
int len = _participants.Length;
var updated = new Participant[len + 1];
Array.Copy(_participants, updated, len);
updated[len] = jumper;
_participants = updated;
}

public void Add(Participant[] jumpers)
{
if (jumpers == null) return;
foreach (var jumper in jumpers)
{
Add(jumper);
}
}

public void Sort()
{
Participant.Sort(_participants);
}
}
}
}
159 changes: 159 additions & 0 deletions Purple_2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
using System;
using System.Linq;

namespace Lab_7
{
public class Purple_2
{
public struct Participant
{
private string _firstName;
private string _lastName;
private int _jumpDistance;
private int[] _styleScores;
private int _targetDistance;

public string Name => _firstName;
public string Surname => _lastName;
public int Distance => _jumpDistance;
public int[] Marks
{
get
{
if (_styleScores == null) return default(int[]);
var copy = new int[_styleScores.Length];
Array.Copy(_styleScores, copy, _styleScores.Length);
return copy;
}
}

public int Result
{
get
{
if (_styleScores == null || _styleScores.Length != 5) return 0;
int[] sorted = new int[5];
Array.Copy(_styleScores, sorted, 5);
Array.Sort(sorted);
int judgePoints = sorted.Skip(1).Take(3).Sum();
int distancePoints = 60 + (_jumpDistance - _targetDistance) * 2;
return Math.Max(0, judgePoints + distancePoints);
}
}

public Participant(string name, string surname)
{
_firstName = name;
_lastName = surname;
_jumpDistance = 0;
_styleScores = new int[5];
_targetDistance = 120;
}

public void Jump(int distance, int[] marks, int target)
{
if (marks == null || marks.Length != 5 || _styleScores == null || _jumpDistance > 0) return;
_jumpDistance = distance;
_targetDistance = target;
Array.Copy(marks, _styleScores, marks.Length);
}

public static void Sort(Participant[] array)
{
if (array == null) return;
for (int i = 1; i < array.Length; i++)
{
var key = array[i];
int j = i - 1;
while (j >= 0 && array[j].Result < key.Result)
{
array[j + 1] = array[j];
j--;
}
array[j + 1] = key;
}
}

public void Print()
{
Console.WriteLine($"{_firstName} {_lastName}");
Console.WriteLine($"Distance: {_jumpDistance}");
Console.Write("Marks: ");
foreach (int mark in _styleScores)
{
Console.Write(mark + " ");
}
Console.WriteLine();
Console.WriteLine("Score: " + Result);
Console.WriteLine();
}
}

public abstract class SkiJumping
{
private string _competitionName;
private int _requiredDistance;
private Participant[] _entries;

public string Name => _competitionName;
public int Standard => _requiredDistance;
public Participant[] Participants => _entries;

public SkiJumping(string name, int standard)
{
_competitionName = name;
_requiredDistance = standard;
_entries = new Participant[0];
}

public void Add(Participant jumper)
{
Array.Resize(ref _entries, _entries.Length + 1);
_entries[^1] = jumper;
}

public void Add(Participant[] jumpers)
{
if (jumpers == null) return;
foreach (var jumper in jumpers)
{
Add(jumper);
}
}

public void Jump(int distance, int[] marks)
{
for (int i = 0; i < _entries.Length; i++)
{
if (_entries[i].Distance == 0)
{
var temp = _entries[i];
temp.Jump(distance, marks, _requiredDistance);
_entries[i] = temp;
break;
}
}
}

public void Print()
{
Console.WriteLine($"Competition: {_competitionName}");
Console.WriteLine($"Target distance: {_requiredDistance}m\n");
foreach (var p in _entries)
{
p.Print();
}
}
}

public class JuniorSkiJumping : SkiJumping
{
public JuniorSkiJumping() : base("100m", 100) { }
}

public class ProSkiJumping : SkiJumping
{
public ProSkiJumping() : base("150m", 150) { }
}
}
}
Loading