+ Нов въпрос
V.Valcheva 0 Точки

Programming Fundamentals Final Exam Retake - 9 August 2019 3. Followers

Здравейте, ще се радвам някой да удари едно рамо. Задачата е 3-та от минал финален изпит. Дава ми 90 от 100. Последният тест гърми.

До колкото разбрах трябва накрая да сортирам само по лайкове, а аз сортирам по sum of likes and comments. Вероятно от там идва грешката, но не знам как да сортирам само по лайкове. Благодаря предварително.

Ето линк към judge: https://judge.softuni.bg/Contests/Practice/Index/1767#2

Линк към моя код: https://pastebin.com/unaZRcag

Условие на задачата:

Followers

Now that Pesho has successfully created an account, he wants to connect with other users and gain as many followers, likes and comments as possible.

Create a program that keeps information about Pesho's followers, likes and comments. Keep a record of the followers, each with the likes and comments Pesho has received from them.

You will be receiving lines with commands until you receive the "Log out" command.  There are four possible commands:

• If the username doesn't exist, add it to your records with the given count of likes.
• If the username exist, increase the count of likes with the given count.
• If the username exists, increase the count of commens with 1.
• Delete all records of the given username. If it doesn’t exist, print:

In the end, you have to print the count of followers, each follower with his/her likes and comments (the sum of likes and comments) sorted in descending order by the likes and then by their username in ascending order in the following format:

{count} followers

...

Input

• You will be receiving lines until you receive the "Log out" command.
• The input will always be valid.

Output

• Print the users with their likes in the format described above.

Examples

 Input Output New follower: gosho Like: gosho: 5 Comment: gosho New follower: gosho New follower: tosho Comment: gosho Comment: tosho Comment: pesho Log out 3 followers gosho: 7 pesho: 1 tosho: 1 Input Output Like: A: 3 Comment: A New follower: B Blocked: A Comment: B Like: C: 5 Like: D: 5 Log out 3 followers C: 5 D: 5 B: 1

Тагове:
0
JSuser 222 Точки

Здравей,

Наистина проблема мисля, че ти е в сортирането, но за да можеш да сортираш отделно по лайкове, трябва да ги записваш отделно от comments. Това няма как да стане с map-а, който имаш сега. Има няколко варианта:

1. Правиш 2 map-а и записваш в тях отделно likes i comments

2. Map  от String i int[2] - на [0] записваш likes, a na [1] comments

3. Map ot String i List - същата идея като горното

Ето моето решение с вариант 2, което дава 100/100, надявам се да ти помогне:

https://pastebin.com/fWei0uqh

Успех!

0
31/03/2020 21:09:53
V.Valcheva 0 Точки

Много благодаря за описателния отговор! Помогна ми и за други задачи :)

0
JSuser 222 Точки

Радвам се, че съм успял да помогна. По-късно се сетих за 4-ти вариант на решение чрез обект, който примема  2 параметъра Likes и Comments.

Поздрави!

0
Munna123 1 Точки

Clients interface with one another through in-game talk, individual informing (inside the Roblox condition), and client discussions.
Players can include others they meet in the game to their companion's list. roblox hack generator A player can have a limit of 200 companions and vast adherents. Players likewise have the choice to join local gatherings.

https://freerobuxplace.xyz/

0