[Homework] C# Fundamentals - Objects and Classes - Задача {5} -Teamwork projects
Здравейте, на въпросната задача ми гърми 2-ри тест от доста време, мисля че проблема е в сортировката на member-ите, която изобщо не работи, бихте ли ми показали как да сортирам по имена member-ите, които се намират в списъка? Може и да не е там проблема, просто да дам някъкви насоки.
код - https://pastebin.com/jbdDhed0
линк към условие - https://judge.softuni.bg/Contests/Compete/Index/1215#4
На същата задача. Кодът ми дава верни отговори на примерните стойности. В джъджа ми дава 33 точки
Кодът ми е този:
using System;
using System.Collections.Generic;
using System.Linq;
public class Team
{
public Team(){}
public Team(string creator, string nameTeam)
{
this.Creator = creator;
this.NameTeam = nameTeam;
Member = new List<string>();
}
public string NameTeam {get; set;}
public string Creator {get; set;}
public List<string> Member {get; set;}
}
public class Program
{
public static void Main()
{
int n = int.Parse(Console.ReadLine());
List<Team> orderWithTeam = new List<Team>();
string currentCreator = null;
string currentNameTeam = null;
string currentMember = null;
for(int i = 0; i < n; i++)
{
string[] input1 = Console.ReadLine()
.Split('-')
.Select(x => x.Trim())
.ToArray();
currentCreator = input1[0];
currentNameTeam = input1[1];
bool isThisTeamExist = CheckisThisTeamExist(orderWithTeam, currentNameTeam);
bool isThisManDableCreating = CheckisThisManDableCreating(orderWithTeam, currentCreator);
if(isThisManDableCreating)
{
Console.WriteLine("{0} cannot create another team!", currentCreator);
}
else if(isThisTeamExist)
{
Console.WriteLine("Team {0} was already created!", currentNameTeam);
}
else
{
Console.WriteLine("Team {0} has been created by {1}!", currentNameTeam,currentCreator);
orderWithTeam.Add(new Team(currentCreator, currentNameTeam));
}
} // end for
string input = null;
while((input = Console.ReadLine()) != "end of assignment")
{
string[] input1 = input
.Split(new[]{'-', '>'}, StringSplitOptions.RemoveEmptyEntries)
.Select(x => x.Trim())
.ToArray();
currentMember = input1[0];
currentNameTeam = input1[1];
bool isThisTeamExist = CheckisThisTeamExist(orderWithTeam, currentNameTeam);
bool isTisManDableJoining = CheckisThisManDableJoining (orderWithTeam, currentMember);
bool isLoosur = CheckIsLoosur (orderWithTeam, currentMember, currentNameTeam);
if(!isThisTeamExist)
{
Console.WriteLine("Team {0} does not exist!", currentNameTeam);
}
else if (isTisManDableJoining || isLoosur)
{
Console.WriteLine("Member {0} cannot join team {1}!", currentMember, currentNameTeam);
}
else // isThisTeamExist + !isTisManBableJoining + !isLoosur
{
GiveNewMember(orderWithTeam, currentMember, currentNameTeam);
} // end base if-else construction
} // end while
foreach (var kvp in orderWithTeam.Where(s => s.Member.Count > 0).OrderByDescending(s => s.Member.Count()))
{
Console.WriteLine("{0}", kvp.NameTeam);
Console.WriteLine("- {0}", kvp.Creator);
foreach(var currentMembers in kvp.Member)
{
Console.WriteLine("-- {0}",currentMembers);
}
}
Console.WriteLine("Teams to disband:");
foreach (var kvp in orderWithTeam.Where(s => s.Member.Count == 0).OrderBy(s => s.NameTeam))
{
Console.WriteLine("{0}", kvp.NameTeam);
}
}
public static bool CheckisThisManDableCreating(List<Team> orderWithTeam, string currentCreator)
{
foreach(var kvp in orderWithTeam)
{
if(kvp.Creator == currentCreator)
{
return true;
}
} // end foreach
return false;
}
public static bool CheckisThisTeamExist(List<Team> orderWithTeam, string currentNameTeam)
{
foreach(var kvp in orderWithTeam)
{
if(kvp.NameTeam == currentNameTeam)
{
return true;
}
} // end foreach
return false;
}
public static bool CheckisThisManDableJoining (List<Team> orderWithTeam, string currentMember)
{
foreach(var kvp in orderWithTeam)
{
if(kvp.Member.Contains(currentMember))
{
return true;
}
} // end foreach
return false;
}
public static bool CheckIsLoosur (List<Team> orderWithTeam, string currentMember, string currentNameTeam)
{
foreach (var kvp in orderWithTeam)
{
if(kvp.Creator == currentMember && kvp.NameTeam == currentNameTeam)
{
return true;
}
}
return false;
}
public static void GiveNewMember(List<Team> orderWithTeam, string currentMember, string currentNameTeam)
{
foreach (var kvp in orderWithTeam)
{
if(kvp.NameTeam == currentNameTeam)
{
kvp.Member.Add(currentMember);
break;
}
}
}
}
// 2
// Didi-PowerPuffsCoders
// Toni-Toni is the best
// Petq->PowerPuffsCoders
// Toni->Toni is the best
// end of assignment
//
// Team PowerPuffsCoders has been created by Didi!
// Team Toni is the best has been created by Toni!
// Member Toni cannot join team Toni is the best!
// PowerPuffsCoders
// - Didi
// -- Petq
// Teams to disband:
// Toni is the best
// 3
// Tatyana-CloneClub
// Helena-CloneClub
// Trifon-AiNaBira
// Pesho->aiNaBira
// Pesho->AiNaBira
// Tatyana->Leda
// PeshO->AiNaBira
// Cossima->CloneClub
// end of assignment
//
// Team CloneClub has been created by Tatyana!
// Team CloneClub was already created!
// Team AiNaBira has been created by Trifon!
// Team aiNaBira does not exist!
// Team Leda does not exist!
// AiNaBira
// - Trifon
// -- Pesho
// -- PeshO
// CloneClub
// - Tatyana
// -- Cossima
// Teams to disband: