Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- namespace ConsoleApp1
- {
- class Student
- {
- public string Name;
- public string Surname;
- public string Data;
- public List<int> Marks;
- public int ResultMark;
- // Пропуски
- //
- public int Omissions;
- private double average_mark;
- private int[,] BetterMarks;
- private int sum;
- // Конструкторы
- public Student(string input)
- {
- var temp = input.Split();
- Name = temp[0];
- Surname = temp[1];
- Data = temp[2];
- Marks = new List<int>();
- for (int i = 3; i < temp.Length; i++)
- {
- // Int32.TryParse(); проверка что число
- if (temp[i].Length == 1 && temp[i][0] == '-')
- {
- Omissions++;
- }
- Marks.Add(Int32.Parse(temp[i]));
- }
- Analyse();
- }
- public Student(string name, string surname, string data, List<int> a)
- {
- Name = name;
- Data = data;
- Surname = surname;
- Marks = a;
- Analyse();
- }
- // Методы
- private void Analyse()
- {
- sum = 0;
- foreach (var i in Marks)
- {
- sum += i;
- }
- GetAverageMark();
- ResultMark = GetRusultMark(average_mark);
- GetBetterMarks();
- }
- private void GetAverageMark()
- {
- average_mark = 0;
- foreach (var i in Marks)
- {
- average_mark += i;
- }
- average_mark = GetAverage(average_mark, Marks.Count);
- }
- private int GetRusultMark(double c)
- {
- return (int)(c + 0.5);
- }
- private double GetAverage(double sum, int count)
- {
- return sum / count;
- }
- private void GetBetterMarks()
- {
- BetterMarks = new int[6, 6];
- for (int i = 0; i < 6; i++)
- {
- // q - оценка, которой будем улучшать
- for (int q = i; q < 6; q++)
- {
- if (i > ResultMark)
- {
- int j = 0;
- for (j = 0; GetRusultMark(GetAverage(sum + j * q, Marks.Count + j)) != i; j++) ;
- BetterMarks[i, q] = j;
- }
- }
- }
- }
- public override string ToString()
- {
- string result = "Info about student " + Name + " " + Surname + "\n" + "Date of Birth: " + Data + "\n" + "Marks: ";
- for (int i = 0; i < Marks.Count; i++)
- {
- result += Marks[i].ToString();
- if (i != Marks.Count - 1)
- {
- result += ", ";
- }
- }
- result += '\n' + "Result mark – " + ResultMark.ToString() + '\n';
- for (int i = 0; i < 6; i++)
- {
- for (int j = 0; j < 6; j++)
- {
- if (BetterMarks[i, j] != 0)
- {
- result += "To get " + i.ToString() + " you have to get " + BetterMarks[i, j].ToString() + " marks " + j.ToString() + '\n';
- }
- }
- }
- return result;
- }
- }
- class Program
- {
- public static int cmp(string a, string b)
- {
- // 1, if a > b, 0 if a == b, -1 if b < a
- int l = Math.Min(a.Length, b.Length);
- for (int i = 0; i < l; i++)
- {
- if (a[i] > b[i])
- {
- return 1;
- } else if (a[i] < b[i])
- {
- return -1;
- }
- }
- if (a.Length < b.Length)
- {
- return -1;
- }
- if (a.Length > b.Length)
- {
- return 1 ;
- }
- return 0;
- }
- static void Main(string[] args)
- {
- StreamReader reader = new StreamReader("data.txt");
- int n = Int32.Parse(reader.ReadLine());
- List<Student> stud = new List<Student>();
- for (int i = 0; i < n; i++)
- {
- string s = reader.ReadLine();
- stud.Add(new Student(s));
- }
- for (int x = 0; x < stud.Count; x++)
- {
- for (int i = 0; i < stud.Count - 1; i++)
- {
- if (cmp(stud[i].Surname, stud[i + 1].Surname) == 1)
- {
- var c = stud[i + 1];
- stud[i + 1] = stud[i];
- stud[i] = c;
- }
- else
- if (cmp(stud[i].Surname, stud[i + 1].Surname) == 0)
- {
- if (cmp(stud[i].Name, stud[i + 1].Name) == 1)
- {
- var c = stud[i + 1];
- stud[i + 1] = stud[i];
- stud[i] = c;
- }
- }
- }
- }
- for (int i = 0; i < stud.Count; i++)
- {
- Console.WriteLine(stud[i].ToString());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement