TopcoderArchiveVisit Topcoder
SRM13 May 2002
SRM 88

BadSpanish

Problem statement, definition, constraints, and public examples.

Problem Statement

PROBLEM STATEMENT

Given a lowercase String, convert it to bad Spanish and return the result.

To convert a String to bad Spanish, you must deal with four cases:
All of these are illustrated in the examples.

(1) All occurences of 'the' appearing as a word by itself (surrounded by spaces
or punctuation) should be changed to 'el' (preserving the surrounding spaces
and punctuation).
(2) All occurences of 'yes' appearing as a word by itself (surrounded by spaces
or punctuation) should be changed to 'si' (preserving the surrounding spaces
and punctuation).
(3) Every word ending in a consonant should have an 'o' appended (preserving
the surrounding spaces and punctuation).  A consonant is every letter except
'a','e','i','o', and 'u'.  ('y' is considered a consonant).
(4) If the String ends with a '!' or an '?', you should add the same '!' or '?'
to the beginning of the String, regardless if there is already one there.  The
'!' or '?' must be the terminating character; if there are spaces after it, do
NOT add it to the beginning of the String. (see the 5th example)

DEFINITION

Class: BadSpanish
Method: translate
Parameters: String
Returns: String
Method signature (be sure your method is public): String translate(String line);

NOTES

- Preserve all punctuation and spaces - convert only words.
- Do not convert 'yes' or 'the' as part of a larger word such as 'their' or
'yesterday'.

TopCoder will ensure the validity of the inputs.  Inputs are valid if all of
the following criteria are met:
- line will have between 0 and 50 characters, inclusive.
- line will consist only of the lowercase letters 'a'-'z', spaces, and the six
punctuation characters ,.?!:;

EXAMPLES

Quotes are for clarity only and are not part of the String.

1)
line: "where is the car?"
the method would return: "?where iso el caro?"

2)
line: "yes, i will go on a date with you."
the method would return: "si, i willo go ono a date witho you."

3)
line: "!ay   caramba!"
the method would return: "!!ayo   caramba!"

4)
line: "yes, yesterday their shoes were the coolest?!"
the method would return: "!si, yesterdayo theiro shoeso were el coolesto?!"

5)
line: "a space after the final ! do i still add one! "
the method would return: "a space aftero el finalo ! do i stillo addo one! "  

6) 
line: "yes the yes the yes!"
the method would return: "!si el si el si!"

7)
line: ""
the method would return: ""

Definition

Class:
BadSpanish
Method:
translate
Parameters:
String
Returns:
String
Method signature:
String translate(String param0)
(be sure your method is public)

Constraints

    Examples

      No public sample cases were explicitly marked for this problem in the original data.

      Back to all problems