Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _04.Average_Grades
- {
- class Student
- {
- public string Name { get; set; }
- public List<double> Grades { get; set; }
- public double AverageGrades { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- List<Student> allStudents = new List<Student>();
- for (int i = 0; i <n; i++)
- {
- Student oneStudent = ReadStudent();
- if (oneStudent.AverageGrades >=5.00)
- {
- allStudents.Add(oneStudent);
- }
- }
- allStudents = allStudents.OrderBy(x => x.Name).ThenByDescending(x => x.AverageGrades).ToList();
- for (int i = 0; i < allStudents.Count; i++)
- {
- Console.WriteLine(string.Join(Environment.NewLine, allStudents[i].Name)+" -> "+
- string.Join(Environment.NewLine, $"{allStudents[i].AverageGrades:F2}"));
- }
- }
- static Student ReadStudent ()
- {
- List<string> inputStudent = Console.ReadLine().Split(' ').ToList();
- string name = inputStudent[0];
- inputStudent.RemoveAt(0);
- Student oneStudent = new Student
- {
- Name = name,
- Grades = inputStudent.Select(double.Parse).ToList(),
- AverageGrades = inputStudent.Select(double.Parse).Average()
- };
- return oneStudent;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment