Advertisement
Guest User

04. Average Grades.Broken80%

a guest
Apr 18th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 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.             int n = int.Parse(Console.ReadLine());
  14.  
  15.             var reslut = new List<Tuple<string, double>>();
  16.  
  17.             var grades = new List<double>();
  18.  
  19.             for (int i = 0; i < n; i++)
  20.             {
  21.                 var input = Console.ReadLine().Split();
  22.  
  23.                 var name = input[0];
  24.  
  25.                 var digit = input.Skip(1).Select(double.Parse).ToArray();
  26.  
  27.                 for (int j = 0; j < input.Length - 1; j++)
  28.                 {
  29.                     grades.Add(digit[j]);
  30.                 }
  31.  
  32.                 if (grades.Average() >= 5)
  33.                 {
  34.                     double sum = grades.Average();
  35.  
  36.                     reslut.Add(Tuple.Create(name, sum));    
  37.                 }
  38.                 grades.Clear();
  39.             }
  40.  
  41.             reslut.Sort();
  42.             reslut.OrderBy(x => x.Item1).ThenByDescending(x => x.Item2);
  43.  
  44.             foreach (var item in reslut)
  45.             {
  46.                 Console.WriteLine("{0} -> {1:F2}", item.Item1, item.Item2);
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement