Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Average_Student_Grades_Lab_Sets_and_Dictionaries
- {
- class Program
- {
- static void Main(string[] args)
- {
- int countStudents = int.Parse(Console.ReadLine());
- Dictionary<string, List<decimal>> grades = new Dictionary<string, List<decimal>>();
- for (int i = 0; i < countStudents; i++)
- {
- string[] inputInfo = Console.ReadLine()
- .Split(" ");
- string name = inputInfo[0];
- decimal grade = decimal.Parse(inputInfo[1]);
- if (!grades.ContainsKey(name))
- {
- grades[name] = new List<decimal>();
- }
- grades[name].Add(grade);
- }
- foreach (var (keys, values) in grades)
- {
- Console.Write($"{keys} -> ");
- foreach (var value in values)
- {
- Console.Write($"{value:f2} ");
- }
- Console.WriteLine($"(avg: {values.Average():f2})");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment