using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace HockeyPenaltyTracker
{
public partial class Form1 : Form
{
private int totalPenaltiesTeam1 = 0;
private int totalPenaltiesTeam2 = 0;
private int totalTimeTeam1 = 0;
private int totalTimeTeam2 = 0;
public Form1()
{
InitializeComponent();
}
private void btnAddPenalty_Click(object sender, EventArgs e)
{
// Предполагается, что есть TextBox для номера команды (txtTeamNumber)
// и ComboBox для продолжительности (cmbPenaltyDuration) с опциями 2, 5 и 10.
int teamNumber = int.Parse(txtTeamNumber.Text);
int penaltyDuration = int.Parse(cmbPenaltyDuration.SelectedItem.ToString());
if (teamNumber == 1)
{
totalPenaltiesTeam1++;
totalTimeTeam1 += penaltyDuration;
}
else if (teamNumber == 2)
{
totalPenaltiesTeam2++;
totalTimeTeam2 += penaltyDuration;
}
// Обновление Label для отображения результатов
lblResultsTeam1.Text = $"Команда 1: {totalPenaltiesTeam1} удалений, {totalTimeTeam1} минут";
lblResultsTeam2.Text = $"Команда 2: {totalPenaltiesTeam2} удалений, {totalTimeTeam2} минут";
}
}
}
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace HockeyPenalties
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void calculateButton_Click(object sender, EventArgs e)
{
// Разделить введенные данные на отдельные строки
string[] team1Penalties = team1TextBox.Text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
string[] team2Penalties = team2TextBox.Text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
// Создать словари для хранения данных о штрафах
Dictionary team1PenaltyCounts = new Dictionary();
Dictionary team2PenaltyCounts = new Dictionary();
// Обработать данные о штрафах для каждой команды
ProcessPenalties(team1Penalties, team1PenaltyCounts);
ProcessPenalties(team2Penalties, team2PenaltyCounts);
// Вывести результаты
team1ResultTextBox.Text = GetResultString(team1PenaltyCounts);
team2ResultTextBox.Text = GetResultString(team2PenaltyCounts);
}
private void ProcessPenalties(string[] penalties, Dictionary penaltyCounts)
{
foreach (string penalty in penalties)
{
int penaltyDuration = int.Parse(penalty.Substring(penalty.Length - 1));
if (!penaltyCounts.ContainsKey(penaltyDuration))
{
penaltyCounts[penaltyDuration] = 1;
}
else
{
penaltyCounts[penaltyDuration]++;
}
}
}
private string GetResultString(Dictionary penaltyCounts)
{
int totalPenalties = 0;
int totalPenaltyTime = 0;
foreach (var penaltyCount in penaltyCounts)
{
totalPenalties += penaltyCount.Value;
totalPenaltyTime += penaltyCount.Key * penaltyCount.Value;
}
return $"Общее число удалений: {totalPenalties}\nОбщее время удалений: {totalPenaltyTime} минут";
}
}
}
string[] data = textBox1.Text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
int team1Count = 0;
int team1Time = 0;
int team2Count = 0;
int team2Time = 0;
foreach (string row in data)
{
string[] parts = row.Split(' ');
int team = int.Parse(parts[0]);
int minutes = int.Parse(parts[1]);
if (team == 1)
{
team1Count++;
team1Time += minutes;
}
else if (team == 2)
{
team2Count++;
team2Time += minutes;
}
}
textBox2.Text = $"Team 1: Count = {team1Count}, Time = {team1Time} minutes\nTeam 2: Count = {team2Count}, Time = {team2Time} minutes";