Advertisement
Guest User

04. Average Grades.Broken

a guest
Apr 18th, 2017
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 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.             SortedDictionary<string, double> reslut = new SortedDictionary<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.                     if (!reslut.ContainsKey(name))
  37.                     {                      
  38.                          reslut.Add(name, sum);
  39.                     }
  40.                     reslut[name] = sum;
  41.                 }
  42.  
  43.                 grades.Clear();
  44.             }
  45.  
  46.             foreach (var item in reslut)
  47.             {
  48.                 Console.WriteLine("{0} -> {1:F2}", item.Key, item.Value);
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement