Структуры: результаты соревнований по фигурному катанию - C#
Формулировка задачи:
Доброго времени суток. Помогите, пожалуйста, с прогой на тему "Структуры".
Условие: Дан файл, содержащий сведения о результатах соревнований по фигурному катанию. Каждая запись содержит фамилию спортсмена и оценки восьми судей. Определить распределение спортсменов по местам.
Дошел пока только вот до этого момента. Он у меня находит среднее значение оценок к. Но вот дальше как их сортировать - не знаю. Может кто подтолкнет? Буду очень благодарен!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Структуры
{
public partial class Form1 : Form
{
public struct abiturient
{
public string fam;
public int sud1;
public int sud2;
public int sud3;
public int sud4;
public int sud5;
public int sud6;
public int sud7;
public int sud8;
}
abiturient[] abit = new abiturient[100];
int n = 0; //строк в файле
public Form1()
{
InitializeComponent();
StreamReader data = new StreamReader("abit.txt", Encoding.Default);
dataGridView1.ColumnCount = 9;
dataGridView1.RowCount = 1;
dataGridView2.ColumnCount = 1;
dataGridView2.RowCount = 1;
dataGridView1.Rows.Add("Фамилия", "Судья 1", "Судья 2", "Судья 3", "Судья 4", "Судья 5", "Судья 6", "Судья 7", "Судья 8");
dataGridView2.Rows.Add("Фамилия", "Судья 1", "Судья 2", "Судья 3", "Судья 4", "Судья 5", "Судья 6", "Судья 7", "Судья 8");
for (n = 0; !data.EndOfStream; n++)
{
string[] temp = data.ReadLine().Split(' ');
abit[n].fam = temp[0];
abit[n].sud1 = Convert.ToInt32(temp[1]);
abit[n].sud2 = Convert.ToInt32(temp[2]);
abit[n].sud3 = Convert.ToInt32(temp[3]);
abit[n].sud4 = Convert.ToInt32(temp[4]);
abit[n].sud5 = Convert.ToInt32(temp[5]);
abit[n].sud6 = Convert.ToInt32(temp[6]);
abit[n].sud7 = Convert.ToInt32(temp[7]);
abit[n].sud8 = Convert.ToInt32(temp[8]);
dataGridView1.Rows.Add(abit[n].fam, abit[n].sud1.ToString(), abit[n].sud2.ToString(), abit[n].sud3.ToString(), abit[n].sud4.ToString(), abit[n].sud5.ToString(), abit[n].sud6.ToString(), abit[n].sud7.ToString(), abit[n].sud8.ToString()); //добавляем новую строку
}
data.Close();
}
private void button3_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button2_Click(object sender, EventArgs e)
{
for (int i = 0; i < n; i++)
{
int k;
k = (abit[i].sud1 + abit[i].sud2 + abit[i].sud3 + abit[i].sud4 + abit[i].sud5 + abit[i].sud6 + abit[i].sud7 + abit[i].sud8)/8;
if //как сортировать??
{
dataGridView2.Rows.Add(abit[i].fam);//, abit[i].sud1.ToString(), abit[i].sud2.ToString(), abit[i].sud3.ToString()); //добавляем новую строку
}
}
button2.Enabled = false;
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}Решение задачи: «Структуры: результаты соревнований по фигурному катанию»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Структуры
{
public partial class Form1 : Form
{
public struct sport
{
public string fam;
public int sud1;
public int sud2;
public int sud3;
public int sud4;
public int sud5;
public int sud6;
public int sud7;
public int sud8;
//эта переменная хранит среднюю оценку
public int ocenka;
//Эта переменная хранит место в общем зачете
public int mesto;
}
sport[] spor = new sport[100];
int n = 0; //строк в файле
public Form1()
{
InitializeComponent();
StreamReader data = new StreamReader("abit.txt", Encoding.Default);
dataGridView1.ColumnCount = 9;
dataGridView1.RowCount = 1;
dataGridView2.ColumnCount = 2;
dataGridView2.RowCount = 1;
dataGridView1.Rows.Add("Фамилия", "Судья 1", "Судья 2", "Судья 3", "Судья 4", "Судья 5", "Судья 6", "Судья 7", "Судья 8");
dataGridView2.Rows.Add("Фамилия", "Баллы");
for (n = 0; !data.EndOfStream; n++)
{
string[] temp = data.ReadLine().Split(' ');
spor[n].fam = temp[0];
spor[n].sud1 = Convert.ToInt32(temp[1]);
spor[n].sud2 = Convert.ToInt32(temp[2]);
spor[n].sud3 = Convert.ToInt32(temp[3]);
spor[n].sud4 = Convert.ToInt32(temp[4]);
spor[n].sud5 = Convert.ToInt32(temp[5]);
spor[n].sud6 = Convert.ToInt32(temp[6]);
spor[n].sud7 = Convert.ToInt32(temp[7]);
spor[n].sud8 = Convert.ToInt32(temp[8]);
dataGridView1.Rows.Add(spor[n].fam, spor[n].sud1.ToString(), spor[n].sud2.ToString(), spor[n].sud3.ToString(), spor[n].sud4.ToString(), spor[n].sud5.ToString(), spor[n].sud6.ToString(), spor[n].sud7.ToString(), spor[n].sud8.ToString()); //добавляем новую строку
}
data.Close();
}
private void button2_Click(object sender, EventArgs e)
{
for (int i = 0; i < n; i++)
{
spor[i].ocenka = (spor[i].sud1 + spor[i].sud2 + spor[i].sud3 + spor[i].sud4 + spor[i].sud5 + spor[i].sud6 + spor[i].sud7 + spor[i].sud8);
dataGridView2.Rows.Add(spor[i].fam, spor[i].ocenka.ToString());
}
button2.Enabled = false;
}
private void выходToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void условиеИАвторToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 A = new Form2();
A.Show();
this.Hide();
}
}
}