TopCoder problem "UnLinker" used in SRM 203 (Division II Level Three)

Problem Statement


You are implementing the portion of an online dating site where members display their profiles. Most of the profile content is automatically generated from member data. Part of a profile, however, is furnished directly by the member as free-form text. Weblinks frequently crop up in this text, despite a site policy that forbids advertisement and linking of any kind. Your job is to seek and destroy all weblinks in a given piece of text.

For the purposes of this problem, a weblink is a string consisting of three parts. From left to right, these are the prefix, domain, and suffix.

The prefix consists of one of the three following strings.


The domain is a sequence of one or more characters, each of which is a letter (a character from 'a' to 'z' or from 'A' to 'Z'), a numeral ('0' to '9'), or a period (the character '.').

The suffix is one of the five following strings.


There must be no space character within the weblink. The weblink may have any kind of character to the left and right of it. It may also occur at the beginning of the text, at the end of the text, or it may itself be the entire text.

Furthermore, a weblink extends as far as possible to the left and right. The passage below, for example, contains a single weblink stretching between the fragments "espi" and "aladocious".


Each weblink in the text must be replaced with a string consisting of the word "OMIT" followed by a number. The first weblink is to be replaced with "OMIT1", the second with "OMIT2", and so forth. All portions of text that do not consist of a weblink must remain intact.

You are given a String consisting of letters, numerals ('0' to '9') and the characters ' ' (space), ',' (comma), '.' (period), ':' (colon), and '/' (slash). Return a String containing the text after it has been cleaned in the manner described above.



Method signature:String clean(String text)
(be sure your method is public)


-text is between 1 and 50 characters long, inclusive
-each character in text is a letter ('a' to 'z' or 'A' to 'Z'), a numeral ('0' to '9'), or one of the following: ' ' (space); ',' (comma); '.' (period); ':' (colon); '/' (slash).


Returns: "espiOMIT1aladocious"
Remember, a weblink stretches as far as possible to the left and right.
"check 4"
Returns: "check OMIT1 4 OMIT2 OMIT3"
Each occurrence of "" gets a different number.
"check 4"
Returns: "check OMIT1 4 OMIT2"
What a difference a space makes!
"check 4"
Returns: "check OMIT1 4 OMIT2OMIT3"
The last two weblinks are separate again.
" goodz 4, 2"
Returns: "OMIT1 goodz 4 OMIT2, 2OMIT3"
Returns: "http.//,OMIT1,www.comhttp://.tv"
Returns: "OMIT1/www"

Problem url:

Problem stats url:




lbackstrom , brett1479

Problem categories:

String Manipulation