Loading...
AnzhelaNurieva avatar AnzhelaNurieva 4 Точки

*ForceBook

решение => https://pastebin.com/KT06wTU9 -> 10/100 имам проблем при сортирането дава ми exeption, но не откривам причината.

задание => 

  1. *ForceBook 

The force users are struggling to remember which side are the different forceUsers from, because they switch them too often. So you are tasked to create a web application to manage their profiles. You should store an information for every unique forceUser, registered in the application. 

You will receive several input lines in one of the following formats: 

{forceSide} | {forceUser} 

{forceUser} -> {forceSide} 

The forceUser and forceSide are strings, containing any character.  

If you receive forceSide | forceUser, you should check if such forceUser already exists, and if not, add him/her to the corresponding side.  

If you receive a forceUser -> forceSide, you should check if there is such a forceUser already and if so, change his/her side. If there is no such forceUser, add him/her to the corresponding forceSide, treating the command as a new registered forceUser. 
Then you should print on the console: "{forceUser} joins the {forceSide} side!"  

You should end your program when you receive the command "Lumpawaroo". At that point you should print each force side, ordered descending by forceUsers count, than ordered by name. For each side print the forceUsers, ordered by name. 

In case there are no forceUsers in a side, you shouldn`t print the side information.  

Input / Constraints 

  • The input comes in the form of commands in one of the formats specified above. 

  • The input ends, when you receive the command "Lumpawaroo". 

Output 

  • As output for each forceSide, ordered descending by forceUsers count, then by name,  you must print all the forceUsers, ordered by name alphabetically. 

  • The output format is: 

Side: {forceSide}, Members: {forceUsers.Count} 

! {forceUser} 

! {forceUser} 

! {forceUser} 

  • In case there are NO forceUsers, don`t print this side.  

Examples 

Input 

Output 

Comments 

Light | Gosho 

Dark | Pesho 

Lumpawaroo 

Side: Dark, Members: 1 

! Pesho 

Side: Light, Members: 1 

! Gosho 

We register Gosho in the Light side and Pesho in the Dark side. After receiving "Lumpawaroo" we print both sides, ordered by membersCount and then by name. 

Lighter | Royal 

Darker | DCay 

Ivan Ivanov -> Lighter 

DCay -> Lighter 

Lumpawaroo 

Ivan Ivanov joins the Lighter side! 

DCay joins the Lighter side! 

Side: Lighter, Members: 3 

! DCay 

! Ivan Ivanov 

! Royal 

Although Ivan Ivanov doesn`t have profile, we register him and add him to the Lighter side. 

We remove DCay from Darker side and add him to Lighter side. 

We print only Lighter side because Darker side has no members. 

 

Тагове:
Axiomatik avatar Axiomatik 2422 Точки

Requirements: If you receive forceSide | forceUser, you should check if such forceUser already exists, and if not, add him/her to the corresponding side.

Include some validation in Line 43-46 to check if the current user is not already present:

                        bool memberPresent = false;
                        foreach (var member in uniqueForceUser[type])
                        {
                            if (member == user)
                            {
                                memberPresent = true;
                                break;
                            }
                        }
                        if (!memberPresent)
                        {
                            uniqueForceUser[type].Add(user);
                        }

 

Check for members present when receiving ForceSide command, here a three separate validations 1. When a member is already in the group and you receive the the same group name, you still have to print out a message 2. When creating a new group, you have to check in the other groups to see if the given user is present and transfer the user to the new group 3. When both groups exists you have to check if the user is present and if so again transfer. Otherwise just add the user to the group.

Example, might be buggy as I did not check in judge, but should give you an idea of what to aim for:

 

else if (isForceUser)
                {
                    bool memberPresent = false;

                    foreach (var (group, members) in uniqueForceUser)
                    {
                        foreach (var member in members)
                        {
                            if (member == user)
                            {
                                Console.WriteLine($"{user} joins the {group} side!");
                                memberPresent = true;
                                break;
                            }
                        }
                    }


                    if (memberPresent)
                    {
                        break;
                    }

                    if (!uniqueForceUser.ContainsKey(type))
                    {
                        uniqueForceUser[type] = new List<string>();

                        foreach (var (group, members) in uniqueForceUser)
                        {
                            bool breakCycle = false;
                            foreach (var member in members)
                            {
                                if (member == user)
                                {
                                    uniqueForceUser[group].Remove(user);
                                    uniqueForceUser[type].Add(user);

                                    Console.WriteLine($"{user} joins the {type} side!");
                                    breakCycle = true;
                                    break;
                                }
                            }
                            if (breakCycle)
                            {
                                break;
                            }
                        }

                    }
                    else
                    {
                        foreach (var (group, members) in uniqueForceUser)
                        {
                            bool breakCycle = false;
                            foreach (var member in members)
                            {
                                if (member == user)
                                {
                                    uniqueForceUser[group].Remove(user);
                                    uniqueForceUser[type].Add(user);

                                    Console.WriteLine($"{user} joins the {type} side!");
                                    breakCycle = true;
                                    break;
                                }
                            }
                            if (breakCycle)
                            {
                                break;
                            }
                        }
                    }

 

Best,

 

0
Axiomatik avatar Axiomatik 2422 Точки

Exception got triggered in your final foreach loop, include x.Value.Count so that the compiler knows what needs to be actually compared (with Count the number of members , without Count ???):

            foreach (var side in uniqueForceUser.OrderByDescending(x => x.Value.Count).ThenBy(y => y.Key))

 

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