Advertisement
anon20016

Untitled

Nov 16th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4.  
  5. namespace ConsoleApp1
  6. {
  7.  
  8. class Student
  9. {
  10. public string Name;
  11. public string Surname;
  12. public string Data;
  13. public List<int> Marks;
  14. public int ResultMark;
  15.  
  16. // Пропуски
  17. //
  18.  
  19. public int Omissions;
  20.  
  21. private double average_mark;
  22. private int[,] BetterMarks;
  23. private int sum;
  24.  
  25. // Конструкторы
  26. public Student(string input)
  27. {
  28. var temp = input.Split();
  29. Name = temp[0];
  30. Surname = temp[1];
  31. Data = temp[2];
  32. Marks = new List<int>();
  33. for (int i = 3; i < temp.Length; i++)
  34. {
  35. // Int32.TryParse(); проверка что число
  36. if (temp[i].Length == 1 && temp[i][0] == '-')
  37. {
  38. Omissions++;
  39. }
  40. Marks.Add(Int32.Parse(temp[i]));
  41. }
  42. Analyse();
  43. }
  44. public Student(string name, string surname, string data, List<int> a)
  45. {
  46. Name = name;
  47. Data = data;
  48. Surname = surname;
  49. Marks = a;
  50. Analyse();
  51. }
  52.  
  53. // Методы
  54. private void Analyse()
  55. {
  56. sum = 0;
  57. foreach (var i in Marks)
  58. {
  59. sum += i;
  60. }
  61. GetAverageMark();
  62. ResultMark = GetRusultMark(average_mark);
  63. GetBetterMarks();
  64. }
  65.  
  66. private void GetAverageMark()
  67. {
  68. average_mark = 0;
  69. foreach (var i in Marks)
  70. {
  71. average_mark += i;
  72. }
  73. average_mark = GetAverage(average_mark, Marks.Count);
  74. }
  75. private int GetRusultMark(double c)
  76. {
  77. return (int)(c + 0.5);
  78. }
  79. private double GetAverage(double sum, int count)
  80. {
  81. return sum / count;
  82. }
  83. private void GetBetterMarks()
  84. {
  85. BetterMarks = new int[6, 6];
  86. for (int i = 0; i < 6; i++)
  87. {
  88. // q - оценка, которой будем улучшать
  89. for (int q = i; q < 6; q++)
  90. {
  91. if (i > ResultMark)
  92. {
  93. int j = 0;
  94. for (j = 0; GetRusultMark(GetAverage(sum + j * q, Marks.Count + j)) != i; j++) ;
  95. BetterMarks[i, q] = j;
  96. }
  97. }
  98. }
  99. }
  100.  
  101. public override string ToString()
  102. {
  103. string result = "Info about student " + Name + " " + Surname + "\n" + "Date of Birth: " + Data + "\n" + "Marks: ";
  104. for (int i = 0; i < Marks.Count; i++)
  105. {
  106. result += Marks[i].ToString();
  107. if (i != Marks.Count - 1)
  108. {
  109. result += ", ";
  110. }
  111. }
  112. result += '\n' + "Result mark – " + ResultMark.ToString() + '\n';
  113.  
  114. for (int i = 0; i < 6; i++)
  115. {
  116. for (int j = 0; j < 6; j++)
  117. {
  118. if (BetterMarks[i, j] != 0)
  119. {
  120. result += "To get " + i.ToString() + " you have to get " + BetterMarks[i, j].ToString() + " marks " + j.ToString() + '\n';
  121. }
  122. }
  123. }
  124.  
  125. return result;
  126. }
  127. }
  128. class Program
  129. {
  130. public static int cmp(string a, string b)
  131. {
  132. // 1, if a > b, 0 if a == b, -1 if b < a
  133.  
  134. int l = Math.Min(a.Length, b.Length);
  135. for (int i = 0; i < l; i++)
  136. {
  137. if (a[i] > b[i])
  138. {
  139. return 1;
  140. } else if (a[i] < b[i])
  141. {
  142. return -1;
  143. }
  144. }
  145. if (a.Length < b.Length)
  146. {
  147. return -1;
  148. }
  149. if (a.Length > b.Length)
  150. {
  151. return 1 ;
  152. }
  153. return 0;
  154. }
  155.  
  156. static void Main(string[] args)
  157. {
  158. StreamReader reader = new StreamReader("data.txt");
  159. int n = Int32.Parse(reader.ReadLine());
  160. List<Student> stud = new List<Student>();
  161. for (int i = 0; i < n; i++)
  162. {
  163. string s = reader.ReadLine();
  164. stud.Add(new Student(s));
  165. }
  166. for (int x = 0; x < stud.Count; x++)
  167. {
  168. for (int i = 0; i < stud.Count - 1; i++)
  169. {
  170. if (cmp(stud[i].Surname, stud[i + 1].Surname) == 1)
  171. {
  172. var c = stud[i + 1];
  173. stud[i + 1] = stud[i];
  174. stud[i] = c;
  175. }
  176. else
  177. if (cmp(stud[i].Surname, stud[i + 1].Surname) == 0)
  178. {
  179. if (cmp(stud[i].Name, stud[i + 1].Name) == 1)
  180. {
  181. var c = stud[i + 1];
  182. stud[i + 1] = stud[i];
  183. stud[i] = c;
  184. }
  185. }
  186. }
  187. }
  188. for (int i = 0; i < stud.Count; i++)
  189. {
  190. Console.WriteLine(stud[i].ToString());
  191. }
  192. }
  193. }
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement