Problem със задача Practice Sessions
В джъдж получавам 80/100. Може ли съдействие от къде може да се получава тази грешка.
Моето решение: https://pastebin.com/erJ851Ue
Линк към judge: https://judge.softuni.bg/Contests/Practice/Index/1594#1
В джъдж получавам 80/100. Може ли съдействие от къде може да се получава тази грешка.
Моето решение: https://pastebin.com/erJ851Ue
Линк към judge: https://judge.softuni.bg/Contests/Practice/Index/1594#1
Everything is OK in your code, however the Add-command validation should only check if a given race-track already exist, but not if a racer is already on that track. With the new Add-validation your code gives 100%.
Refactored code :
using System;
using System.Collections.Generic;
using System.Linq;
namespace _02._Practise_sessions
{
class Program
{
static void Main(string[] args)
{
Dictionary<string, List<string>> list = new Dictionary<string, List<string>>();
string input = string.Empty;
string[] separators = { "->" };
while ((input = Console.ReadLine()) != "END")
{
string[] comands = input.Split(separators, StringSplitOptions.RemoveEmptyEntries);
if (comands.Length == 0)
{
continue;
}
if (comands[0] == "Add")
{
string road = comands[1];
string racer = comands[2];
if (!list.ContainsKey(road))
{
list.Add(road, new List<string>());
}
list[road].Add(racer);
//if (!list.ContainsKey(road))
//{
// list.Add(road, new List<string>());
// list[road].Add(racer);
//}
//else
//{
// if (list[road].Contains(racer))
// {
// continue;
// }
// list[road].Add(racer);
//}
}
else if (comands[0] == "Move")
{
string currentRoad = comands[1];
string racer = comands[2];
string nextRoad = comands[3];
if (list[currentRoad].Contains(racer) && !list[nextRoad].Contains(racer))
{
list[currentRoad].Remove(racer);
list[nextRoad].Add(racer);
}
}
else if (comands[0] == "Close")
{
string road = comands[1];
if (list.ContainsKey(road))
{
list.Remove(road);
}
}
}
var result = list
.OrderByDescending(a => a.Value.Count)
.ThenBy(b => b.Key).ToDictionary(a => a.Key, b => b.Value);
Console.WriteLine("Practice sessions:");
Print(result);
}
public static void Print(Dictionary<string, List<string>> list)
{
foreach (var item in list)
{
string roadName = item.Key;
Console.WriteLine(roadName);
foreach (var item1 in item.Value)
{
Console.WriteLine($"++{item1}");
}
}
}
}
}