Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Average_student_grades
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, List<double>> students = new Dictionary<string, List<double>>();
- int cnt = int.Parse(Console.ReadLine());
- for (int i = 0; i < cnt; i++)
- {
- string[] input = Console.ReadLine().Split(' ').ToArray();
- string name = input[0];
- double grade = double.Parse(input[1]);
- if (!students.ContainsKey(name))
- {
- students.Add(name, new List<double>());
- }
- students[name].Add(grade);
- }
- foreach (KeyValuePair<string, List<double>> student in students)
- {
- string printName = student.Key;
- List<double> grades = student.Value;
- double avg = grades.Average();
- Console.Write($"{printName} -> ");
- foreach (double grade in grades)
- {
- Console.Write($"{grade:f2} ");
- }
- Console.WriteLine($"(avg: {avg:f2})");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement