2. Average Student Grades
Здравейте, това е решението ми https://pastebin.com/cdTwbvEa на задача 2. Average Student Grades от Lab: Sets and Dictionaries Advanced.
Някой знае ли защо джъджа ми дава само 50/100?
Здравейте, това е решението ми https://pastebin.com/cdTwbvEa на задача 2. Average Student Grades от Lab: Sets and Dictionaries Advanced.
Някой знае ли защо джъджа ми дава само 50/100?
Code:
using System;
using System.Collections.Generic;
using System.Linq;
namespace _02._Average_Student_Grades
{
class Program
{
static void Main(string[] args)
{
int numGrades = int.Parse(Console.ReadLine());
Dictionary<string, List<decimal>> studentInfo = new Dictionary<string, List<decimal>>();
for (int i = 0; i < numGrades; i++)
{
string[] gradeInfo = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
string name = gradeInfo[0];
decimal grade = Convert.ToDecimal(gradeInfo[1]);
if (!studentInfo.ContainsKey(name))
{
studentInfo.Add(name, new List<decimal>() { grade });
}
else
{
studentInfo[name].Add(grade);
}
}
foreach (var student in studentInfo)
{
// Individual grades and average grades must be formatted with F2, otherwise will not pass with grades such as 4.2323, 5.222 ...
Console.WriteLine($"{student.Key} -> {string.Join(' ', student.Value.Select(grade => grade.ToString("F2")))} (avg: {student.Value.Average():f2})");
}
}
}
}
Благодаря!