Софтуерно Инженерство
Loading...
Vesolini avatar Vesolini 5 Точки

9. *ForceBook Associative Arrays

Здравейте банда,

Може ли някой да ми помогне. Опитвам се да реша по долната задача, но judge ми дава 90/100. Кода ми е това -> https://pastebin.com/8PnJLGKk. Знам че може да се понапише една идея по разбираемо, но ще съм благодарен, ако някой ми каже къде бъркам по този начин написано. Също така, ако някой има предложение или идея как да се оптимизира, ще се радвам да я разбера!

Благодаря :)

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.

 

Тагове:
0
Fundamentals Module
Iv_Konov avatar Iv_Konov 354 Точки
Best Answer

Здравей,

 

Условието е:

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

т.е. дали изобщо съществува, а не само в текущия forceSide.

===

if (input.Contains("|"))
                {
                    string[] array = input.Split(" | ").ToArray();
                    string firstCommand = array[0];
                    string secondCommand = array[1];                    

                    if (!dict.Any(x => x.Value.Contains(secondCommand)))
                    {
                        if (!dict.ContainsKey(firstCommand))
                        {
                            dict[firstCommand] = new List<string>();
                        }

                        //if (!dict[firstCommand].Contains(secondCommand))
                        //{
                        //    dict[firstCommand].Add(secondCommand);
                        //}

                        dict[firstCommand].Add(secondCommand);
                    }
                }

===

 

Поздрави,

Иван

1
Vesolini avatar Vesolini 5 Точки

Благодаря за отговора. Изглежда не съм разбрал правилно условието, но сега вече ми се изясни :)

1
Iv_Konov avatar Iv_Konov 354 Точки

Здравей,

 

Според мен, винаги трябва да имаш едно на ум със стойностите (Value) на ключовете, особено ако условието на задачата не ти е съвсем ясно - дали стойностите трябва да са уникални в речника или не... Аз лично в подобни случаи си поставям въпросителни на проверката, т.е. че има вероятност за грешка и да ме подсети да пробвам различен вид проверка.

 

Поздрави,

Иван

0