Compile time error => 02. Average Student Grades [Dictionaries and LINQ - Lab]
Zdrавейте! Ако може някой да ми обясни защо получавам тази грешка.
Условие: https://softuni.bg/downloads/svn/soft-tech/Sept-2017/Programming-Fundamentals-Extended-November-2017/04.%20Programming-Fundamentals-Extended-Dictionaries-and-LINQ/04.%20Programming-Fundamentals-Extended-Dictionaries-and-LINQ-Lab.docx // Задача 02.
Мое решение: с дадените примери получавам коректен резултат, включително и с форматирането.
using System;
using System.Collections.Generic;
using System.Linq;
namespace Lab
{
class Program
{
static void Main(string[] args)
{
Average_Sudents_Grade();
}
private static void Average_Sudents_Grade()
{
var n = int.Parse(Console.ReadLine());
Dictionary<string, List<double>> students = new Dictionary<string, List<double>>();
for (int i = 0; i < n; i++)
{
string[] info = Console.ReadLine().Split(" ").ToArray();
string name = info[0];
double grade = double.Parse(info[1]);
//
if (!students.ContainsKey(name))
{
List<double> temp = new List<double>();
temp.Add(grade);
students.Add(name, temp);
}
else
{
students[name].Add(grade);
}
}
foreach (var pair in students)
{
Console.Write($"{pair.Key} ->");
foreach (var item in pair.Value)
{
Console.Write($" {item:f2}");
}
Console.WriteLine($" (avg: {pair.Value.Average():F2})");
}
}
private static void P01()
{
string[] sequenc = Console.ReadLine().ToLower().Split(' ').ToArray();
var dict = new Dictionary<string, int>();
//
foreach (var word in sequenc)
{
if (!dict.ContainsKey(word))
{
dict.Add(word, 1);
}
else
{
dict[word]++;
}
}
List<string> str = new List<string>();
foreach (var pair in dict)
{
if (pair.Value % 2 != 0)
{
str.Add(pair.Key);
}
}
Console.WriteLine(string.Join(", ", str));
}
}
}
Да, очевидно! Благодаря!