Statistics

Problem Statement for "Chat"

Problem Statement

PROBLEM STATEMENT:

You are working on a new chat enhancement for the contest applet.  The client
is asking for you to scan the chat text and expand any abbreviation found
within the text.  Example:  let's say the user entered in "Admins: when are
systest starting" and that "systest" is an abbreviation for "System Tests".
Your function will expand that abbreviation within the text and return "Admins:
when are System Tests starting".

Class name: Chat
Method name: expandAbbr
Parameters: String, String[]
Returns: String

Implement a class Chat, which contains a method expandAbbr.  This method takes
a String representing the chat text and a String[] representing the
abbreviations and returns a String of the chat text with all abbreviations
expanded.

The method signature is:
String expandAbbr(String chatText, String[] abbr);
Be sure you method is public.

TopCoder will ensure the validity of the inputs. Inputs are valid if all of the
following criteria are met:
*The chatText will contain from 0 (zero) to 50 characters inclusive.
*The chatText will contain characters 'A'-'Z', 'a'-'z', '0'-'9', ' ' (spaces),
'.' (period), ':' (colon) and ',' (comma).
*The abbr will contain from 0 (zero) to 50 elements inclusive.
*Each element of the abbr will be from 3 to 50 characters inclusive.
*Each element of the abbr will be formatted like: "<abbreviation>:<expansion>"
(quotes and angle brackets for clarity only) where
<abbreviation> - will contain the characters 'A-Z', 'a-z', and '0-9' and
will contain at least 1 character
a single colon (":") will represent the separator between the abbreviation
and the expansion text
<expansion> represents the expansion text - it will contain characters
'A'-'Z', 'a'-'z', '0'-'9', ' ' (spaces), '.' (period), ':' (colon) and ','
(comma).  It will contain at least one character.
*Each abbreviation in abbr will be unique - you cannot have {"is:to", "is:from"}.

Notes:
*The abbreviation is CASE SENSITIVE (an <abbreviation> of "LO" is not the same
as "Lo") - see example 2.
*An abbreviation in the chat text will be delimited by ' ' (spaces), '.'
(period), ':' (colon) and ',' (comma).  Example:  if you had a chat text of "A,
B.C. D: E ABC", then the possible abbreviations would be "A", "B", "C", "D",
"E" or "ABC".
*When you expand an abbreviation - do NOT expand any abbrevations that may
appear in the expanded text.  Example:  if you had an abbreviation like
"ABBA:ABBA is great" - the ABBA in the expansion text would NOT get expanded
(see example 3).
*An abbreviation can appear zero or more times within the chat text (see
examples 1 and 5).
*A single colon (":") represents the separator between the abbreviation and the
expansion text.  The expansion text itself MAY ALSO contain colons.  If it
does, the first colon encountered represents the separator and all other colons
should be considered part of the expansion text (see example 7).

Examples:
if your input was {"Howdy Lo.", {"LO:Logan"}} - you would return "Howdy Lo."
No expansions happened.
if your input was {"Howdy Lo.", {"LO:Logan","Lo:Louie"}} - you would return
"Howdy Louie.".  You expanded "Lo" to "Louie".
if your input was {"Howdy Lo.", {"LO:Logan","Lo:Lo Louie LO"}} - you would
return "Howdy Lo Louie LO.".  You expanded "Lo" to "Lo Louie LO" and the
"Lo"/"LO" in the expanded text does NOT get expanded.
if your input was {"System error in 1 2.", {"1:Chat","2:Text"}} - you would
return "System error in Chat Text.".
if your input was {"1: System error in 1 2.", {"1:Chat","2:Text"}} - you would
return "Chat: System error in Chat Text.".
if your input was {"12: System error in .1.2.", {"1:Chat","2:Text"}} - you
would return "12: System error in .Chat.Text.".
if your input was {"..,,::A:,a", {"A:::"}} - (the abbreviation "A" gets
replaced by expansion text "::") - you would return "..,,:::::,a".
if your input was {"This is a good example.", {"good:bad","bad:great"}} - you
would return "This is a bad example.".

Definition

Class:
Chat
Method:
expandAbbr
Parameters:
String, String[]
Returns:
String
Method signature:
String expandAbbr(String param0, String[] param1)
(be sure your method is public)

Constraints

    Examples


      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: