vstoyanov

Untitled

Oct 25th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.84 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 _04.Average_Grades
  8. {
  9.     class Student
  10.     {
  11.         public string Name { get; set; }
  12.  
  13.         public List<double> Grades { get; set; }
  14.  
  15.         public double AverageGrades { get; set; }
  16.     }
  17.  
  18.  
  19.  
  20.     class Program
  21.     {
  22.         static void Main(string[] args)
  23.         {
  24.             int n = int.Parse(Console.ReadLine());
  25.  
  26.             List<Student> allStudents = new List<Student>();
  27.            
  28.  
  29.             for (int i = 0; i <n; i++)
  30.             {
  31.                 Student oneStudent = ReadStudent();
  32.  
  33.  
  34.                 if (oneStudent.AverageGrades >=5.00)
  35.                 {
  36.                     allStudents.Add(oneStudent);
  37.  
  38.                 }
  39.                
  40.  
  41.             }
  42.  
  43.            
  44.  
  45.            
  46.  
  47.             allStudents = allStudents.OrderBy(x => x.Name).ThenByDescending(x => x.AverageGrades).ToList();
  48.  
  49.             for (int i = 0; i < allStudents.Count; i++)
  50.             {
  51.  
  52.  
  53.                 Console.WriteLine(string.Join(Environment.NewLine, allStudents[i].Name)+" -> "+
  54.                     string.Join(Environment.NewLine, $"{allStudents[i].AverageGrades:F2}"));
  55.                    
  56.  
  57.             }
  58.  
  59.  
  60.         }
  61.  
  62.         static Student ReadStudent ()
  63.         {
  64.            List<string> inputStudent = Console.ReadLine().Split(' ').ToList();
  65.  
  66.             string name = inputStudent[0];
  67.             inputStudent.RemoveAt(0);
  68.             Student oneStudent = new Student
  69.             {
  70.                 Name = name,
  71.  
  72.  
  73.                 Grades = inputStudent.Select(double.Parse).ToList(),
  74.  
  75.                 AverageGrades = inputStudent.Select(double.Parse).Average()
  76.                
  77.             };
  78.            
  79.  
  80.  
  81.  
  82.  
  83.             return oneStudent;
  84.         }
  85.  
  86.  
  87.  
  88.  
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment