Loading...
Emberclap avatar Emberclap 6 Точки

5. Teamwork Projects

Здравейте,

някой има ли престава, къде изпускам нещо. От 3-ти събмит ми дава грешка в тест 2, пробвал съм различни инпути и различни тестове при всички проверки и продължавам да не виждам, какъв е проблема. Разгледах и другите решения из нета, няма нужда да ми изпращате вашето, идеята ми е да разбера къде аз бъркам. Благодаря предварително.

https://softuni.bg/downloads/svn/soft-tech/May-2023/CSharp/06.%20CSharp-Fundamentals-Objects-and-Classes/06.%20CSharp-Fundamentals-Objects-and-Classes-Exercise.pdf

Моят код. https://pastebin.com/P4yhTLiW

Тагове:
0
Fundamentals Module 25/06/2023 19:24:55
Axiomatik avatar Axiomatik 2422 Точки

I have seen one possible issue in your code, keep in mind not tested. When printing your final result, you check the members count if more than 1 instead of 0 (the Members List should not contain the creator of the team).

 
                if (team.Members.Count > 0)
                {
                    Console.WriteLine($"{team.TeamName}");
                    Console.WriteLine($"- {team.Creator}");
                    for (int i = 1; i < team.Members.Count; i++)
                    {
                        Console.WriteLine($"-- {team.Members[i]}");
                    }
 
                }

 

Demo code =>

using System;
using System.Linq;
using System.Collections.Generic;

namespace teamworkProject
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            List<Team> teamList = new List<Team>();

            for (int i = 0; i < n; i++)
            {
                string[] teamCreator = Console.ReadLine().Split('-');
                string creator = teamCreator[0];
                string teamName = teamCreator[1];
                TeamCreator(teamList, creator, teamName);

            }

            string memberInput = Console.ReadLine();
            while (memberInput != "end of assignment")
            {
                string[] memberSplit = memberInput.Split("->");
                string member = memberSplit[0];
                string teamName = memberSplit[1];
                bool creatorCheck = CreatorCheck(member, teamName, teamList);
                if (creatorCheck == false)
                {
                    MemberCreator(teamList, member, teamName);
                }
                memberInput = Console.ReadLine();
            }

            teamList = teamList.OrderByDescending(x => x.Members.Count).ThenBy(x => x.TeamName).ToList();
            foreach (var team in teamList)
            {
                team.Members.Sort();
            }
            TeamPrinter(teamList);

            List<Team> noMemberTeams = new List<Team>();
            NoMemberPrinter(noMemberTeams, teamList);

        }

        static bool CreatorCheck(string member,string teamName, List<Team> teamList)
        {
            bool creatorCheck = false;

            foreach (var team in teamList)
            {
                if (team.Creator == member && team.TeamName == teamName)
                {
                    Console.WriteLine($"Member {member} cannot join team {team.TeamName}!");
                    creatorCheck = true;
                    return creatorCheck;
                }
                else if (team.Creator == member && team.TeamName != teamName)
                {
                    Console.WriteLine($"{member} cannot create another team!");
                    creatorCheck = true;
                    return creatorCheck;
                }
            }

            return creatorCheck;
        }

        static void NoMemberPrinter(List<Team> noMemberTeams, List<Team> teamList)
        {
            foreach (var team in teamList)
            {
                if (team.Members.Count == 0)
                {
                    Team newTeam = new Team(team.Creator, team.TeamName);
                    noMemberTeams.Add(newTeam);
                }
            }
            noMemberTeams = noMemberTeams.OrderBy(x => x.TeamName).ToList();
            Console.WriteLine("Teams to disband:");
            foreach (var team in noMemberTeams)
            {
                Console.WriteLine($"{team.TeamName}");
            }

        }

        static void TeamPrinter(List<Team> teamList)
        {
            foreach (var team in teamList)
            {
                if (team.Members.Count > 0)
                {
                    Console.WriteLine($"{team.TeamName}");
                    Console.WriteLine($"- {team.Creator}");
                    foreach (var person in team.Members)
                    {
                        Console.WriteLine($"-- {person}");
                    }
                }
            }
        }

        static List<Team> MemberCreator(List<Team> teamList, string member, string teamName)
        {
            bool teamFail = true;
            bool memberFail = false;
            foreach (var team in teamList)
            {
                if (team.TeamName == teamName)
                {
                    teamFail = false;
                }
            }
            if (teamFail)
            {
                Console.WriteLine($"Team {teamName} does not exist!");
                return teamList;
            }

            foreach (var team in teamList)
            {
                foreach (var person in team.Members)
                {
                    if (person == member)
                    {
                        memberFail = true;
                    }
                }
            }
            if (memberFail)
            {
                Console.WriteLine($"Member {member} cannot join team {teamName}!");
                return teamList;
            }

            foreach (var team in teamList)
            {
                if (team.TeamName == teamName)
                {
                    team.Members.Add(member);
                    break;
                }
            }

            return teamList;
        }


        static List<Team> TeamCreator(List<Team> teamList, string creator, string teamName)
        {
            foreach (var team in teamList)
            {
                if (teamName == team.TeamName)
                {
                    Console.WriteLine($"Team {teamName} was already created!");
                    return teamList;
                }
            }

            foreach (var team in teamList)
            {
                if (creator == team.Creator)
                {
                    Console.WriteLine($"{creator} cannot create another team!");
                    return teamList;
                }
            }

            Team newTeam = new Team(creator, teamName);
            teamList.Add(newTeam);
            Console.WriteLine($"Team {teamName} has been created by {creator}!");
            return teamList;
        }
    }

    class Team
    {
        public string Creator { get; set; }

        public string TeamName { get; set; }

        public List<string> Members { get; set; }

        public Team(string creator, string teamName)
        {
            Creator = creator;
            TeamName = teamName;
            Members = new List<string>();
        }
    }
}

 

 

 

0
Emberclap avatar Emberclap 6 Точки

First - thank you for your time!

The reason why my last checks are like that, is actualy because my Creator is team member, BUT your right it shouldn't be. i'm using for cicle for teams with more than 1 member, and start reading from index 1, just to skip the first member that is also the Creator, however it may cause problems in some of other test. I will change the code a litle bit and will find out.

Again, thanks alot for your time.

0
Emberclap avatar Emberclap 6 Точки

OK, i found my mistake, and its rly dumb one but.... "For each team, you have to print its members sorted by
name (ascending). " i didnt do that....

i did sort team by members.count and TeamName, but never sorted the members... and the time that consume.... atleast now i can give my mind a rest.

It's mine new code and as @ Axiomatik suggest i remove teamCreator from team.

if anyone is interested https://pastebin.com/8EywHagV .

1
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.