Loading...

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

Paco8409 avatar Paco8409 1 Точки

Проблем със задача 02. Mirror Words от 03. Programming Fundamentals Final Exam Retake 90/100

Здравейте колеги. Бих се радвал, ако някой ми помогне да отрия грешката в кода си.В Judge ми дава 90/100, с грешен отговор на 9-ти тест.Доста време и отделих на задачата, пробвах да я счупя с доста и всевъзможни варианти на input, за които се сетих, но всички които пробвах минаха успешно. Разгледах и други решения на същата задача, които дават 100/100, но те са с друг подход. Наистина бих се радвал да отрия точно в моя код къде е грешката и ще съм благодарен някой да помогне. Благодаря предварително !

Ето и моето решение: https://pastebin.com/i1TCvqfk

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

Programming Fundamentals Final Exam Retake 10.04.2020

Problem 2. Mirror words

 

The SoftUni Spelling Bee competition is here. But it`s not like any other Spelling Bee competition out there, it`s different and a lot more fun! You, of course, are a participant and you are eager to show the competition that you are the best, so go ahead, learn the rules and win!

On the first line of the input you will be given a text string. In order to win the competition you have to find all hidden word pairs, read them and mark the ones that are mirror images of each other.

First of all you have to extract the hidden word pairs. Hidden word pairs are:

  • Surrounded by "@" or "#" (only one of the two) in the following pattern #wordOne##wordTwo# or @wordOne@@wordTwo@
  • At least 3 characters long each (without the surrounding symbols)
  • Made up of letters only

If the second word, spelled backwards is the same as the first word and vice versa (casing matters!), then they are a match and you have to store them somewhere. Examples of mirror words:

#Part##traP# @leveL@@Level@ #sAw##wAs#

  • If you don`t find any valid pairs print: "No word pairs found!"
  • If you find valid pairs print their count: "{valid pairs count} word pairs found!"
  • If there are no mirror words print: "No mirror words!"
  • If there are mirror words print:

"The mirror words are:

{wordOne} <=> {wordtwo}, {wordOne} <=> {wordtwo}, {wordOne} <=> {wordtwo}, etc…"

Input / Constraints

  • You will recive a string.

Output

  • Print the proper output messages in the proper cases as described in the problem description.
  • If there are pairs of mirror words, print them in the end, each pair separated by ", ".
  • Each pair of mirror word must be printed with " <=> " between the words.

Examples

Input

@mix#tix3dj#poOl##loOp#wl@@bong&song%4very$long@thong#Part##traP##@@leveL@@Level@##car#rac##tu@pack@@ckap@#rr#sAw##wAs#r#@w1r     

Output

Comments

5 word pairs found!

The mirror words are:

Part <=> traP, leveL <=> Level, sAw <=> wAs

There are 5 green and yellow pairs that meet all requirements and thus are valid.

#poOl##loOp# is valid and looks very much like a mirror words pair but it isn`t because the casings don`t match.

#car#rac# “rac” spelled backwards is "car" but this is not a valid pair because there is only one "#" between the words.

@pack@@ckap@ is also valid but "ckap" backwards is "pakc" which is not the same as "pack", so they are not mirror words.

 

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

Грешката е в регекса:

@"\#{1}[A-z]{3,}\#{2,}[A-z]{3,}\#{1}|\@{1}[A-z]{3,}\@{2,}[A-z]{3,}\@{1}"

Трябва да е:

@"\#{1}[A-z]{3,}\#{2}[A-z]{3,}\#{1}|\@{1}[A-z]{3,}\@{2}[A-z]{3,}\@{1}"

Инаще ще хваща като валидни двойки примерно:

@Part@@@traP@

0
Paco8409 avatar Paco8409 1 Точки

Много благодаря ! 

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