Advertisement
Aborigenius

Nested_StudentsGrades

Jul 15th, 2017
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 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 Task1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int N = int.Parse(Console.ReadLine());
  14.             Dictionary<string, List<double>> grades = new Dictionary<string, List<double>>();
  15.  
  16.             for (int i = 0; i < N; i++)
  17.             {
  18.                 string[] input = Console.ReadLine().Split(' ');
  19.                 string name = input[0];
  20.                 double grade = double.Parse(input[1]);
  21.  
  22.                 if (!grades.ContainsKey(name))
  23.                 {
  24.                     grades[name] = new List<double>();
  25.                 }
  26.                         grades[name].Add(grade);
  27.                
  28.             }
  29.             foreach (KeyValuePair<string, List<double>> item in grades)
  30.             {
  31.                 string name = item.Key;
  32.                 List<double> studentsGrades = item.Value;
  33.                 double average = studentsGrades.Average();
  34.                 Console.Write($"{name} -> ");
  35.                 foreach (var value in studentsGrades)
  36.                 {
  37.                     Console.Write($"{value:f2} ");
  38.                 }
  39.                 Console.WriteLine($"(avg: {average:f2})");
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement