Statistics

Problem Statement for "UnLinker"

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.


    http://
    http://www.
    www.

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.


    .com
    .org
    .edu
    .info
    .tv

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".


    espihttp://www.tv.org.superwww.cali.comaladocious

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.

Definition

Class:
UnLinker
Method:
clean
Parameters:
String
Returns:
String
Method signature:
String clean(String text)
(be sure your method is public)

Constraints

  • 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).

Examples

  1. "espihttp://www.tv.org.superwww.cali.comaladocious"

    Returns: "espiOMIT1aladocious"

    Remember, a weblink stretches as far as possible to the left and right.

  2. "check www.foo.com 4 www.foo.com www.scoopz.com"

    Returns: "check OMIT1 4 OMIT2 OMIT3"

    Each occurrence of "www.foo.com" gets a different number.

  3. "check www.foo.com 4 www.foo.comwww.scoopz.com"

    Returns: "check OMIT1 4 OMIT2"

    What a difference a space makes!

  4. "check www.foo.com 4 www.foo.comhttp://scoopz.com"

    Returns: "check OMIT1 4 OMIT2OMIT3"

    The last two weblinks are separate again.

  5. "http://411.com goodz 4 www.733t.com, 2http://..com"

    Returns: "OMIT1 goodz 4 OMIT2, 2OMIT3"

  6. "http.//say.org,www.jeeves.x.info,www.comhttp://.tv"

    Returns: "http.//say.org,OMIT1,www.comhttp://.tv"

  7. "D.eduinfoox.comDHwww.ttp://htwww./www.hyGqowP8L zX"

    Returns: "D.eduinfoox.comDHwww.ttp://htwww./www.hyGqowP8L zX"

  8. "O4:http://www.infoY0pBwww..HxbmX5ID.edueduE9www.os"

    Returns: "O4:OMIT1eduE9www.os"

  9. "1uCJ7Dwww. Sxgz.tvAd.tvJCyAwww..http://www.tvDgHvH"

    Returns: "1uCJ7Dwww. Sxgz.tvAd.tvJCyAwww..OMIT1DgHvH"

  10. "W.comqV.info.cW.http://www.p.tva.com:opwww.vTgf5jC"

    Returns: "W.comqV.info.cW.OMIT1:opwww.vTgf5jC"

  11. "C.orgsXP2.eduS.orgw.http://wwwww.tt.tv/www.CxdPc8g"

    Returns: "C.orgsXP2.eduS.orgw.OMIT1/www.CxdPc8g"

  12. "yL.Z wOlw.infofwww.7.infottp://,2w81www.mqoS0uTimq"

    Returns: "yL.Z wOlw.infofOMIT1ttp://,2w81www.mqoS0uTimq"

  13. "OH,Z,6Y5H5V3Cwwhttp://www.Mh55..com.orgtp://com7Bg"

    Returns: "OH,Z,6Y5H5V3CwwOMIT1tp://com7Bg"

  14. ".t.inwww.oihk1,8j873www.U7Uww.org/TGfBBEBvqCn1TpO5"

    Returns: ".t.inwww.oihk1,8j873OMIT1/TGfBBEBvqCn1TpO5"

  15. "2jhz rjWp48TMlAq,dfU SElM,TtRwww.o/.org.edu..tvouT"

    Returns: "2jhz rjWp48TMlAq,dfU SElM,TtRwww.o/.org.edu..tvouT"

  16. "jht.infonfo.ww.nx.mLtj7w.tvOwww.http://www.Yhe yq"

    Returns: "jht.infonfo.ww.nx.mLtj7w.tvOwww.http://www.Yhe yq"

  17. "J/.tvO3d L.4A .tvLcMYwww.N.tvp://w.orgrr.iwww.. UQ"

    Returns: "J/.tvO3d L.4A .tvLcMYOMIT1p://w.orgrr.iwww.. UQ"

  18. "http://ommQwTDg.orgJDWght.org/www..edup.tvT4 ZUj0,"

    Returns: "OMIT1/OMIT2T4 ZUj0,"

  19. "www..qhttp://ww.dThttp://Lh.edutNU4Nx.tvW.info Ou7"

    Returns: "www..qhttp://ww.dTOMIT1 Ou7"

  20. "NYG65XNd.tv.PPw.hywww.uwm.com.comw.http://www.TUlc"

    Returns: "NYG65XNd.tv.PPw.hyOMIT1w.http://www.TUlc"

  21. ".combdfC1htwww./www.twww./www...tvQY28ig.tvinfoJXS"

    Returns: ".combdfC1htwww./www.twww./OMIT1infoJXS"

  22. "oHerJyi.infotvAN1rf http://www.wwww.ww.MfBhG www.k"

    Returns: "oHerJyi.infotvAN1rf http://www.wwww.ww.MfBhG www.k"

  23. "/QxZQ.info qwww.hwww.//ww.infoB ,q.info1mi.tvww.HR"

    Returns: "/QxZQ.info qwww.hwww.//ww.infoB ,q.info1mi.tvww.HR"

  24. "H 2.tv2HPF.orghttwww.vww.g7GMhttp:/www...eduJO/AzF"

    Returns: "H 2.tv2HPF.orghttwww.vww.g7GMhttp:/OMIT1JO/AzF"

  25. "NJjZOJHmiog3wwhttp://91www.info.orww.orgTF.tvKkFWs"

    Returns: "NJjZOJHmiog3wwOMIT1KkFWs"

  26. "q,Rp3.tvt.ewwwww.ebwww.UQ.info5:.edup.tvwww.www.AW"

    Returns: "q,Rp3.tvt.ewwOMIT15:.edup.tvwww.www.AW"

  27. ".org.com.xKubCUVy.tvhttp://.tvIWDA http://www.KO7Y"

    Returns: ".org.com.xKubCUVy.tvhttp://.tvIWDA http://www.KO7Y"

  28. ".orgRwww.http://.orgeFG/l2t www.w.iwww.vFh.eduxbMv"

    Returns: ".orgRwww.http://.orgeFG/l2t OMIT1xbMv"

  29. "qbw.t.eduwww.eduwwww.pTrrGE:8m7ret0.o.orgOv:SnJuOI"

    Returns: "qbw.t.eduwww.eduwwww.pTrrGE:8m7ret0.o.orgOv:SnJuOI"

  30. "JUP OQh.infoWrh9fG.orgttphttp://i.comwww.KLwwwww.X"

    Returns: "JUP OQh.infoWrh9fG.orgttpOMIT1www.KLwwwww.X"

  31. "rM5jhttp://.comBtw.comghttp://scm.edu5wSh.cowww..m"

    Returns: "rM5jOMIT1gOMIT25wSh.cowww..m"

  32. "tE0prTc7 Jva CTl.tv.tv64Rbowww.EPwXqhttp://w.infoR"

    Returns: "tE0prTc7 Jva CTl.tv.tv64Rbowww.EPwXqOMIT1R"

  33. "www.JIh.com//bNB.wwwww.rg0s5h tbU.tvHO4F.tvkU.orgn"

    Returns: "OMIT1//bNB.wwwww.rg0s5h tbU.tvHO4F.tvkU.orgn"

  34. "f.eduw.1v.orgc 4e/nqKiuAmqUmwww..cwww.tp://B.tvur7"

    Returns: "f.eduw.1v.orgc 4e/nqKiuAmqUmwww..cwww.tp://B.tvur7"

  35. "UbE2l,jy.comww.w.orgin.comvwwwww..6:L4FgSDQ1rh,ph,"

    Returns: "UbE2l,jy.comww.w.orgin.comvwwwww..6:L4FgSDQ1rh,ph,"

  36. "http.orgww..e.tvYdnwMNE4jhttp://www.m1www..vaFvxQh"

    Returns: "http.orgww..e.tvYdnwMNE4jhttp://www.m1www..vaFvxQh"

  37. ",,www.Hwww.www.j:jFs http://www..eduRLw.ed.com19X "

    Returns: ",,www.Hwww.www.j:jFs OMIT119X "

  38. "hwww.rg/www..infoOe.infoZ8www.org .org.Y4Q3 www.cy"

    Returns: "hwww.rg/OMIT1 .org.Y4Q3 www.cy"

  39. ".bTNh.tv://www.whttp://www.I3gnYwww.A07Rwww.f.tv5N"

    Returns: ".bTNh.tv://www.wOMIT15N"

  40. "J.1.comxgFhttp://p:.tvomJ3YFBQ/eI.comykDcPwww.eaVI"

    Returns: "J.1.comxgFhttp://p:.tvomJ3YFBQ/eI.comykDcPwww.eaVI"

  41. "N.edu://www.w.A4/knwNwww.RwI.edusK lwww.mowww.eduY"

    Returns: "N.edu://www.w.A4/knwNOMIT1sK lOMIT2Y"

  42. "oP0ye.edu.com://www. hrwww..com://cwww.iG0Dq:.Vlll"

    Returns: "oP0ye.edu.com://www. hrwww..com://cwww.iG0Dq:.Vlll"

  43. "1Rql .com.I.tvtvw.comAhttp://www.zZhttp://www.hT.C"

    Returns: "1Rql .com.I.tvtvw.comAhttp://www.zZhttp://www.hT.C"

  44. "PeBKgD P3http:///www.rgtwww.tvc4a.com.tvf2gAZwww. "

    Returns: "PeBKgD P3http:///OMIT1f2gAZwww. "

  45. "IC9KoiHYr Gwww.F.comJJ e kwww.wwwhttp.tv.infouWZiD"

    Returns: "IC9KoiHYr GOMIT1JJ e kOMIT2uWZiD"

  46. "Zu7yiI4 .eduuj.o.orgww.www.ht.edwww.orgpll.xx6uL3O"

    Returns: "Zu7yiI4 .eduuj.o.orgww.OMIT1pll.xx6uL3O"

  47. "Lcx.com.K:uhttp:/www.o.comgNXoVH7http://www.7/sDdN"

    Returns: "Lcx.com.K:uhttp:/OMIT1gNXoVH7http://www.7/sDdN"

  48. "/wu.eduwww.edu://bY8dehttp://p://.tv.infowww.OM, J"

    Returns: "/wu.eduwww.edu://bY8dehttp://p://.tv.infowww.OM, J"

  49. "Qwww.6UhsS.com.ww.nW2I.http://www.foPn4Qv9w.orgIqh"

    Returns: "QOMIT1.ww.nW2I.OMIT2Iqh"

  50. "Ce8CT0MLNm NKhttpwww.omwww.infoaukjhttp://..comYLS"

    Returns: "Ce8CT0MLNm NKhttpOMIT1aukjOMIT2YLS"

  51. "http://www.www.com/www"

    Returns: "OMIT1/www"

  52. "www.link.com.link.com"

    Returns: "OMIT1"

  53. "OMIT OMIT www.sdf.com"

    Returns: "OMIT OMIT OMIT1"

  54. "espihttp://www.tvporg"

    Returns: "espiOMIT1porg"

  55. "abchttp:www.abc.com"

    Returns: "abchttp:OMIT1"

  56. "hello http://aaacom hello"

    Returns: "hello http://aaacom hello"


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: