• 34

Learning Opportunities

This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.



Oh no, the keyboard is sticky and sometimes keys have repeated twice and sometimes keys haven't been activated after pressed. Not only that but the problem wasn't discovered until after some documents have been written.

Fortunately, the problem isn't too bad and only happens once in a while. Instead of retyping all the documents you will write a program to correct the issue.

Your program will read a document and use the document as both the source to find correct words and to fix words with missing letters or letters that are duplicated by accident. Preserve the placement of all non-letters, like punctuation.

For example the following document

once upon a little while,
the moon came out and began to smile.
smile it-did all night long,
until the sun arose at dawn.
iit-did linger high in broad day light,
before under cloud it dd take flight.

Here we have two examples of 'it' spelt correctly to fix the one instance of 'iit'
and two examples of 'did' spelt correctly to fix the one instance of 'dd'

The incorrect word must have less instances than the number of instances the correct word. Therefore 'did' is not changed to 'dd', because 'did' has 2 instances and 'dd' only has 1.

Incorrect words have either 1 letter doubled (like 'iit') or 1 letter missing (like 'dd') but not both. For example 'dii' should not be corrected to 'did' if 'dii' existed in the above document.

Do not use words that are not in the document, for example do not hard code common English words. There is no guarantee that the words in the documents are English or any Earthly language. Also, the documents are precisely crafted such that they will only work if the only vocabulary that is used is from the document itself.
line 1 : integer N number of lines
next N lines: Document lines
N lines: Corrected document lines
The document length is less than 20 lines and less than 256 characters per line. "Words" consist only of lower case ascii characters from a-z. For example isn't is considered 2 words isn and t because the ' cannot be inside a word for this puzzle.
dont fix it
dont fix it

A higher resolution is required to access the IDE