题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1804
Deli Deli
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1577 Accepted Submission(s): 866
Problem Description
Mrs. Deli is running the delicatessen store "Deli Deli". Last year Mrs. Deli has decided to expand her business and build up an online store. She has hired a programmer who has implemented the online store.
Recently some of her new online customers complained about the electronic bills. The programmer had forgotten to use the plural form in case that an item is purchased multiple times. Unfortunaly the programmer of Mrs. Deli is on holiday and now it is your task to implement this feature for Mrs. Deli. Here is a description how to make the plural form:
1. If the word is in the list of irregular words replace it with the given plural.
2. Else if the word ends in a consonant followed by "y", replace "y" with "ies".
3. Else if the word ends in "o", "s", "ch", "sh" or "x", append "es" to the word.
4. Else append "s" to the word.
Recently some of her new online customers complained about the electronic bills. The programmer had forgotten to use the plural form in case that an item is purchased multiple times. Unfortunaly the programmer of Mrs. Deli is on holiday and now it is your task to implement this feature for Mrs. Deli. Here is a description how to make the plural form:
1. If the word is in the list of irregular words replace it with the given plural.
2. Else if the word ends in a consonant followed by "y", replace "y" with "ies".
3. Else if the word ends in "o", "s", "ch", "sh" or "x", append "es" to the word.
4. Else append "s" to the word.
Input
The first line of the input file consists of two integers L and N (0 ≤ L ≤ 20, 1 ≤ N ≤ 100). The following L lines contain the description of the irregular words and their plural form. Each line consists of two words separated by a space character, where the first word is the singular, the second word the plural form of some irregular word. After the list of irregular words, the following N lines contain one word each, which you have to make plural. You may assume that each word consists of at most 20 lowercase letters from the english alphabet ('a' to 'z').
Output
Print N lines of output, where the i
th line is the plural form of the i
th input word.
Sample Input
3 7 rice rice spaghetti spaghetti octopus octopi rice lobster spaghetti strawberry octopus peach turkey
Sample Output
rice lobsters spaghetti strawberries octopi peaches turkeys
水题吧,按照题目要求来即可。
<pre name="code" class="cpp">#include<iostream>
#include<map>
using namespace std;
bool judge1(string s)
{
int i=s.size()-1;
if(s[i]!='y') return 0;
if(i>0&&s[i-1]!='a'&&s[i-1]!='e'&&s[i-1]!='i'&&s[i-1]!='o'&&s[i-1]!='u') return 1;
return 0;
}
bool judge2(string s)
{
int i=s.size()-1;
if(s[i]=='o'||s[i]=='s'||s[i]=='x') return 1;
if(i>0&&(s[i]=='h'&&(s[i-1]=='c'||s[i-1]=='s'))) return 1;
return 0;
}
int main()
{
int n,m;
string a,b;
while(cin>>n>>m)
{
map<string,string>Map;
for(int i=0;i<n;i++)
{
cin>>a>>b;
Map[a]=b;
}
for(int i=0;i<m;i++)
{
cin>>a;
if(Map.find(a)!=Map.end()) cout<<Map[a]<<endl;
else if(judge1(a))
{
a[a.size()-1]='i';
a+="es";
cout<<a<<endl;
}
else if(judge2(a))
{
a+="es";
cout<<a<<endl;
}
else
{
a+="s";
cout<<a<<endl;
}
}
}
return 0;
}