Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace LabP01CountSameValuesInArray
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, List<decimal>> map = new Dictionary<string, List<decimal>>();
- int n = int.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- string[] input = Console.ReadLine()
- .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- string name = input[0];
- decimal grade = decimal.Parse(input[1]);
- if (map.ContainsKey(name) == false)
- {
- map.Add(name, new List<decimal>());
- }
- map[name].Add(grade);
- }
- foreach (var student in map)
- {
- var nameOfStudent = student.Key;
- var listOfGrades = student.Value;
- decimal average = listOfGrades.Average();
- Console.WriteLine($"{nameOfStudent} -> {string.Join(" ",listOfGrades):F2} (avg: {average:f2})");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement