Advertisement
Guest User

04. Average Grades.100%

a guest
Apr 21st, 2017
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. namespace ConsoleApplication1
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.     using System.Globalization;
  7.     using System.Numerics;
  8.  
  9.     public class ConsoleApplication1
  10.     {
  11.         public static void Main(string[] args)
  12.         {
  13.  
  14.             int n = int.Parse(Console.ReadLine());
  15.  
  16.             var reslut = new List<Tuple<string, double>>();
  17.  
  18.             var grades = new List<double>();
  19.  
  20.             for (int i = 0; i < n; i++)
  21.             {
  22.                 var input = Console.ReadLine().Split();
  23.  
  24.                 var name = input[0];
  25.  
  26.                 var digit = input.Skip(1).Select(double.Parse).ToArray();
  27.  
  28.                 for (int j = 0; j < input.Length - 1; j++)
  29.                 {
  30.                     grades.Add(digit[j]);
  31.                 }
  32.  
  33.                 if (grades.Average() >= 5)
  34.                 {
  35.                     double sum = grades.Average();
  36.  
  37.                     reslut.Add(Tuple.Create(name, sum));
  38.                 }
  39.                 grades.Clear();
  40.             }
  41.  
  42.             reslut.Sort();
  43.            
  44.  
  45.             foreach (var item in reslut.OrderBy(x => x.Item1).ThenByDescending(x => x.Item2))
  46.             {
  47.                 Console.WriteLine("{0} -> {1:F2}", item.Item1, item.Item2);
  48.             }
  49.         }
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement