Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

Val3ntinV avatar Val3ntinV 20 Точки

StrategyPattern 80т.

https://pastebin.com/ebtM4UtA - Person

https://pastebin.com/3VxFY7JZ - Main

Гърми последния тест - не знам къде да търся грешката ! Ще се радвам за малко помощ !!!

Условие

| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |

An interesting pattern you may have heard of is the Strategy Pattern, if we have multiple ways to do a task (let's say sort a collection) it allows the client to choose the way that most fits his needs. A famous implementation of the pattern in Java is the Collections.sort() method that takes a Comparator.

Create a class Person that holds name and age. Create 2 Comparators for Person (classes which implement the Comparator<Person> interface). The first comparator should compare people based on the length of their name as a first parameter, if 2 people have a name with the same length, perform a case-insensitive compare based on the first letter of their name instead. The second comparator should compare them based on their age. Create 2 TreeSets of type Person, the first should implement the name comparator and the second should implement the age comparator.

Input

On the first line of input you will receive a number N. On each of the next N lines you will receive information about people in the format "<name> <age>". Add the people from the input into both sets (both sets should hold all the people passed in from the input).

Output

Foreach the sets and print each person from the set on a new line in the same format that you received them. Start with the set that implements the name comparator.

Constraints

  • A person’s name will be a string that contains only alphanumerical characters with a length between [1…50] symbols.
  • A person’s age will be a positive integer between [1…100].
  • The number of people N will be a positive integer between [0…100].

Examples

Input

Output

3

Pesho 20

Joro 100

Pencho 1

Joro 100

Pesho 20

Pencho 1

Pencho 1

Pesho 20

Joro 100

5

Ivan 17

asen 33

Stoqn 25

Nasko 99

Joro 3

asen 33

Ivan 17

Joro 3

Nasko 99

Stoqn 25

Joro 3

Ivan 17

Stoqn 25

asen 33

Nasko 99

Тагове:
0
Java Advanced 11/02/2020 18:41:15
Thozed avatar Thozed 1 Точки

Thanks for this useful knowledge. I will definitely apply it to my Elastic Man. This game is a tenderness and humor to bring joy to everyone.

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