For your convienence:
endingsAR = {"o","as","a","amos","ais","an"};
endingsER = {"o","es","e","emos","eis","en"};
endingsIR = {"o","es","e","imos","is","en"};
PROBLEM STATEMENT
In the Spanish language, the infinitives of verbs (such as "to be", "to eat",
or "to beat") all end in the letters "ar", "er", or "ir". In order to
conjugate these verbs in the present tense, you must remove the "ar", "er", or
"ir" and add an appropriate ending, based on the person (i.e. first, second, or
third person) and number (singular or plural) of the verb, and its previous
ending.
For "ar" verbs:
First person singular ends in "o".
Second person singular ends in "as".
Third person singular ends in "a".
First person plural ends in "amos".
Second person plural ends in "ais".
Third person plural ends in "an".
For "er" verbs:
First person singular ends in "o".
Second person singular ends in "es".
Third person singular ends in "e".
First person plural ends in "emos".
Second person plural ends in "eis".
Third person plural ends in "en".
For "ir" verbs:
First person singular ends in "o".
Second person singular ends in "es".
Third person singular ends in "e".
First person plural ends in "imos".
Second person plural ends in "is".
Third person plural ends in "en".
All the verbs you will be dealing with in this problem are special types of
verbs called "stem changers". These are certain verbs in the Spanish language
that have to change their stem (anything preceding the last "ar", "er", or
"ir") before conjugation.
Define the "stem vowel" to mean the last vowel in the verb before the ending.
Note: Vowels are "a", "e", "i", "o", and "u". ("y" is never a vowel in Spanish
except in the word "y", which doesn't end in "ar","er",or "ir", and therefore
you will never see it. In other words, "y" is not considered a vowel in this
problem.)
To conjugate a stem changing verb, take the stem vowel and replace it with the
specified string, then conjugate as normal, by removing the ending and applying
the conjugated ending. One stipulation to this, is that if the requested verb
form is the first or second person plural, no stem changing occurs.
Create the class StemChange containing the method conjugate which takes the
verb to be conjugated, the replacement string for the stem vowel, an integer
representing the person (first, second, or third person, represented as 1, 2,
and 3, respectively), and a string, "singular" or "plural". This will return
the conjugated form of the Spanish infinitive, with the stem changed (if
necessary).
DEFINITION
Class: StemChange
Method: conjugate
Parameters: String, String, int, String
Returns: String
Method signature (be sure your method is public): String conjugate(String verb,
String replacement, int person, String number);
Topcoder will ensure the validity of the inputs. Inputs are considered valid
if all of the following criteria are met:
-verb ends with "ar", "er", or "ir".
-verb contains a stem vowel.
-verb is between 3 and 50 characters in length, inclusive.
-verb and replacement contain only lowercase letters.
-replacement is between 0 and 50 characters in length, inclusive.
-person is 1, 2, or 3.
-number is "singular" or "plural".
EXAMPLES
1.
conjugate("tener","ie",3,"singular") returns "tiene"
The stem vowel "e" is replaced with "ie", then the ending "er" is replaced with
"e".
2.
conjugate("tener","ie",1,"singular") returns "tieno"
Note: This is not the correct way to conjugate "tener" in the first person
singular in the actual Spanish language, but for this problem it is what we are
looking for.
3.
conjugate("tener","ie",1,"plural") returns "tenemos"
For first and second person plural, you do not change the stem.
4.
conjugate("comer","xij",3,"plural") returns "cxijmen"
This is not EVEN CLOSE to real Spanish, but it does fit the problem statement.
5.
conjugate("despertar","ie",1,"singular") returns "despierto"
Remember, the stem vowel is the LAST vowel before the suffix.
6.
conjugate("venir","ie",2,"plural") returns "venis"
7.
conjugate("poder","ue",2,"singular") returns "puedes"
8.
conjugate("abcdefghijklmnopqrstuvwxyzar","bummonkey",3,"plural") returns
"abcdefghijklmnopqrstbummonkeyvwxyzan"
9.
conjugate("oir","",1,"singular") returns "o".