Deli Deli

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 869    Accepted Submission(s): 486

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. 

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 ith line is the plural form of the ith 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

Source

2007~2008 University of Ulm Local Contest

解题报告:这道题是关于单词的复数问题,按照规则做即可,先把特殊的存起来,输入一个新单词时,现在特殊里面找,找到就输出,否则就按照题目所给的规则输出;

代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N =110;
struct node
{
char a[N], b[N];
}word[25];
char str[N];
int main()
{
int n, m, i, len, j, flag;
scanf("%d%d", &n, &m);
for (i = 0; i < n; ++i)
{
scanf("%s%s", word[i].a, word[i].b);
}
for (i = 0; i < m; ++i)
{
scanf("%s", str);
len = strlen(str);
flag = 1;
for (j = 0; j < n; ++j)//匹配
{
if (strcmp(str, word[j].a) == 0)
{
printf("%s\n", word[j].b);
flag = 0;
break;
}
}
if (flag)//说明在特殊表中没有这个单词
{
if (str[len - 1] == 'y' && str[len - 2] != 'a' && str[len - 2] != 'e' && str[len - 2] != 'i' && str[len - 2] != 'o' && str[len - 2] != 'u')
{
for (j = 0; j < len - 1; ++j)
{
printf("%c", str[j]);
}
printf("ies\n");
}
else if (str[len - 1] == 'o' || str[len - 1] == 's' ||str[len - 1] == 'x'||(str[len - 1] == 'h'&&(str[len - 2] == 'c' || str[len - 2] == 's')))
{
for (j = 0; j < len; ++j)
{
printf("%c", str[j]);
}
printf("es\n");
}
else
{
for (j = 0; j < len; ++j)
{
printf("%c", str[j]);
}
printf("s\n");
}
}
}
return 0;
}



posted on 2012-03-11 17:45  Stephen Li  阅读(352)  评论(0编辑  收藏  举报