Advertisement
Spocoman

04. Students

Dec 29th, 2022
1,178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Students
  6. {
  7.     class Program
  8.     {
  9.         public static void Main()
  10.         {
  11.             List<Students> students = new List<Students>();
  12.             int n = int.Parse(Console.ReadLine());
  13.  
  14.             for (int i = 0; i < n; i++)
  15.             {
  16.                 string[] info = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
  17.                 students.Add(new Students(info[0], info[1], double.Parse(info[2])));
  18.             }
  19.  
  20.             Console.WriteLine(String.Join("\n", students.OrderByDescending(x => x.Grade).ToList()));
  21.         }
  22.  
  23.         public class Students
  24.         {
  25.             public Students(string firstName, string secondName, double grade)
  26.             {
  27.                 FirstName = firstName;
  28.                 SecondName = secondName;
  29.                 Grade = grade;
  30.             }
  31.  
  32.             public string FirstName { get; set; }
  33.  
  34.             public string SecondName { get; set; }
  35.  
  36.             public double Grade { get; set; }
  37.  
  38.             public override string ToString()
  39.             {
  40.                 return $"{FirstName} {SecondName}: {Grade:F2}";
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement