Advertisement
Guest User

04.Students

a guest
Feb 23rd, 2020
1,445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _4.Average_Grades
  8. {
  9. class Student
  10. {
  11. public string FirstName { get; set; }
  12. public string SecondName { get; set; }
  13. public double Grade { get; set; }
  14. public Student(string firstName, string secondName, double grade)
  15. {
  16. this.FirstName = firstName;
  17. this.SecondName = secondName;
  18. this.Grade = grade;
  19. }
  20. public double getGrade()
  21. {
  22. return this.Grade;
  23. }
  24.  
  25. public override string ToString()
  26. {
  27. return string.Format(this.FirstName, this.SecondName, this.Grade);
  28. }
  29. }
  30.  
  31.  
  32. class Program
  33. {
  34. static void Main(string[] args)
  35. {
  36. List<Student> students = new List<Student>();
  37. int n = int.Parse(Console.ReadLine());
  38.  
  39. for (int i = 0; i < n; i++)
  40. {
  41. string[] info = Console.ReadLine().Split(" ");
  42. string firstName = info[0];
  43. string secondName = info[1];
  44. double grade = double.Parse(info[2]);
  45.  
  46. Student student = new Student(firstName, secondName, grade);
  47. students.Add(student);
  48.  
  49. //Console.WriteLine($"{student.FirstName} {student.SecondName}: {student.Grade:f2}");
  50.  
  51. }
  52. students.OrderByDescending(t => t.Grade).ThenBy(t => t.FirstName).ToList();
  53. List<Student> sortedStudents = students.OrderByDescending(t => t.Grade).ThenBy(t => t.FirstName).ThenBy(t => t.SecondName).ToList();
  54.  
  55. foreach (Student t in sortedStudents)
  56. {
  57. Console.WriteLine($"{t.FirstName} {t.SecondName}: {t.Grade:f2}");
  58. }
  59.  
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement