Advertisement
veno0o

Untitled

May 6th, 2020
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Numerics;
  6. using System.Runtime.CompilerServices;
  7.  
  8.  
  9. namespace ConsoleApp9
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             var input = int.Parse(Console.ReadLine());
  16.             var dict = new Dictionary<string,List<double>>();
  17.             for (int i = 0; i < input; i++)
  18.             {
  19.                 string[] command = Console.ReadLine().Split(" ",StringSplitOptions.RemoveEmptyEntries).ToArray();
  20.                 string name = command[0];
  21.                 double grade = double.Parse(command[1]);
  22.  
  23.                 if (!dict.ContainsKey(name))
  24.                 {
  25.                     dict.Add(name,new List<double>());
  26.                    
  27.                 }
  28.                
  29.                     dict[name].Add(grade);
  30.                
  31.             }
  32.  
  33.            
  34.             foreach (var grades in dict)
  35.             {
  36.  
  37.                 Console.Write($"{grades.Key} -> ");
  38.                 foreach (var number in grades.Value)
  39.                 {
  40.                     Console.Write($"{number:F2} ");
  41.                    
  42.                 }
  43.  
  44.                 Console.Write($"(avg: {grades.Value.Average():F2})");
  45.                 Console.WriteLine();
  46.                
  47.                
  48.             }
  49.  
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement