UVa 11233 – Deli Deli
Mrs. Deli runs a delicatessen called "Deli Deli."
Just last year, Mrs. Deli decided to expand her business by establishing an online store and hired an engineer to manage the online shop.
Lately, her new customers have been complaining about errors in their electronic bills. The engineer forgot to use the plural form for items when customers purchased multiple items.
Unfortunately, Mrs. Deli's engineer is currently on vacation. Therefore, your task is to implement this feature for Mrs. Deli.
Here are the output instructions for plural forms:
If the plural form of a word belongs to the irregular type, please output the corresponding plural form from the table provided in advance.).
Otherwise, if a word ends with a consonant letter followed by "y," replace "y" with "ies."
Otherwise, if a word ends with "o," "s," "ch," "sh," or "x," add "es" to the end of the word.
Otherwise, simply add "s" to the end of the word.
Sample Inputs/Outputs
Sample Input(s) | Sample Output(s) |
---|---|
The first line of input contains two integers, L and N (0 ≤ L ≤ 20, 1 ≤ N ≤ 100). Next, L lines contain descriptions of irregular words and their plural forms. Each line contains two words separated by a space character, where the first word is the singular form and the second word is the plural form. Following the list of irregular words, there are N lines, each containing a single word. Each word contains at most 20 lowercase letters (a-z). | For each word, output its plural form. |
3 7 rice rice spaghetti spaghetti octopus octopi rice lobster spaghetti strawberry octopus peach turkey | rice lobsters spaghetti strawberries octopi peaches turkeys |
Thought Process
Use a map to record irregular plural forms. If the map does not contain a plural form for a word, it will return an empty string ("").
If the plural form of a word has not been declared in advance, determine it according to the rules mentioned above.
Sample Code-ZeroJudge E268: Deli Deli
#include <iostream>
#include <map>
using namespace std;
bool vowel (char ch)
{
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') return true;
return false;
}
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int L, N;
cin >> L >> N;
map<string, string>MAP;
for (int i = 0; i<L; i++)
{
string a, b;
cin >> a >> b;
MAP[a] = b;
}
for (int i = 0; i<N; i++)
{
string str;
cin >> str;
char last = str[str.length()-1];
if (MAP[str] != "") str = MAP[str];
else if (last == 'y' && !vowel(str[str.length()-2]))
{
str[str.length()-1] = 'i';
str += "es";
}
else if (last == 'o' || last == 's' || last == 'x') str += "es";
else if (last == 'h' && (str[str.length()-2] == 'c' || str[str.length()-2] == 's')) str += "es";
else str += "s";
cout << str << "\n";
}
}
//ZeroJudge E268
//Dr. SeanXD