02. Mirror Words - 03. Programming Fundamentals Final Exam Retake - 88/100
02. Mirror Words
On the first line of the input, you will be given a text string. 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 backward, is the same as the first word and vice versa (casing matters!), 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}"
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 backward is "car", but this is not a valid pair because there is only one "#" between the words. @pack@@ckap@ is also valid, but "ckap" backward is "pakc" which is not the same as "pack", so they are not mirror words. |
Здравейте! Прегледах си кода и условието на задачата многократно, но не мога да видя къде ми е грешката... дава ми 88/100, като гърми на Test #7 . Всякакви входни данни пробвах да подам, работи нормално. Явно ще е някое изключение, за което не се сещам...
Това ми е кодът - https://pastebin.com/KTxNQ8D1