Loading...

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

korchevalex avatar korchevalex 0 Точки

Regular Expressions - More Exercise - 01. Winning Ticket

Здравейте,

Не успях да си намеря проблема в кода: https://pastebin.com/47kbLaB3

1.   Winning Ticket

The lottery is exciting. What is not is checking a million tickets for winnings only by hand. So, you are given the task of creating a program that automatically checks if a ticket is a winner.

You are given a collection of tickets separated by commas and spaces. You need to check every one of them if it has a winning combination of symbols.

A valid ticket should have exactly 20 characters. The winning symbols are '@', '#', '$' and '^'. But for a ticket to be a winner, the symbol should uninterruptedly repeat at least 6 times in both the ticket left half and the ticket right half.

For example, a valid winning ticket should be something like this:

"Cash$$$$$$Ca$$$$$$sh"

The left half "Cash$$$$$$" contains "$$$$$$", which is also contained in the ticket right half "Ca$$$$$$sh". A winning ticket should contain symbols repeating up to 10 times in both halves, which is considered a Jackpot (for example: "$$$$$$$$$$$$$$$$$$$$").

Input

The input will be read from the console. The input consists of a single line containing all tickets separated by commas and one or more white spaces in the format:

  • "{ticket}, {ticket}, … {ticket}"

Output

Print the result for every ticket in the order of their appearance, each on a separate line in the format:

  • "invalid ticket" - Invalid ticket
  • "ticket "{ticket}" - no match" - no match
  • "ticket "{ticket}" - {match length}{match symbol}" - Match with length 6 to 9
  • "ticket "{ticket}" - {match length}{match symbol} Jackpot!" - Match with length 10

Constraints

  • The number of tickets will be in the range [0 … 100].

Examples

Input

Output

Cash$$$$$$Ca$$$$$$sh

ticket "Cash$$$$$$Ca$$$$$$sh" - 6$

$$$$$$$$$$$$$$$$$$$$, aabb  , th@@@@@@eemo@@@@@@ey

ticket "$$$$$$$$$$$$$$$$$$$$" - 10$ Jackpot!

invalid ticket

ticket "th@@@@@@eemo@@@@@@ey" - 6@

validticketnomatch:(

ticket "validticketnomatch:(" - no match

Тагове:
0
Java Fundamentals
icowwww avatar icowwww 2673 Точки
Best Answer

Здравей,

Не прокриваш случая, когато в лявата част имаш 6 символа, но завършва с например 2 от същите символи, а във втората започва с 4 от тези символи.

Например:

^^^^^^Ca^^^^^^shCash

Добавих условие na 18-ред да проверява дали групата от символи се съдържа във втората група:

String symbolGroup = matcher.group("symbol");
String secondPart = ticket.substring(ticket.length()-10);
if(!secondPart.contains(symbolGroup)){
    System.out.printf("ticket \"%s\" - no match%n", ticket);
    continue;
}

 

Проблема е същия като в тема: https://softuni.bg/forum/20221/04-winning-ticket

2
20/03/2023 01:15:01
nimeberi avatar nimeberi 4 Точки

Hello! I want to ask you for what type of games does this work? It looks like a lottery. I have always thought that lotteries and casino games have the lowest chance of winning for players. That's why I only use sports betting  - https://melbet-ca.com/ It's all legal in Canada and open to any adult fan.

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