HDU 1804:Deli Deli

Deli Deli

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1708    Accepted Submission(s): 942

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

如果要延长数组的话,记得要加\0哦~~当然也可以用stract...

AC-code:

#include<cstdio>
#include<cstring>
#define max(a,b) a>b?a:b
char str[25];
int m;
struct node
{
	char s1[25],s2[25];
}s[25];
int f(char ch)
{
	char *yuan="aeiou";
	for(int i=0;i<5;i++)
		if(ch==yuan[i])
			return 0;
	return 1;
}
void check(int l)
{
	int i;
	for(i=0;i<m;i++)
		if(!strcmp(s[i].s1,str))
		{
			printf("%s\n",s[i].s2);
			return ;
		}
	if(str[l-1]=='y'&&f(str[l-2]))
	{
		str[l-1]='i';
		str[l]='e';
		str[l+1]='s';
		str[l+2]='\0';
		printf("%s\n",str);
		return;
	}
	if(str[l-1]=='o'||str[l-1]=='s'||str[l-1]=='x')
	{
		str[l]='e';
		str[l+1]='s';
		str[l+2]='\0';
		printf("%s\n",str);
		return ;
	}
	if(l>1&&(str[l-1]=='h'&&(str[l-2]=='c'||str[l-2]=='s')))
	{
		str[l]='e';
		str[l+1]='s';
		str[l+2]='\0';
		printf("%s\n",str);
		return ;
	}
	printf("%ss\n",str);
	return ;
}
int main()
{
	int n,i,l;
	scanf("%d%d",&m,&n);
		for(i=0;i<m;i++)
			scanf("%s%s",s[i].s1,s[i].s2);
		for(i=0;i<n;i++)
		{
			scanf("%s",str);
			l=strlen(str);
			check(l);
		}
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-03 20:34:07

HDU 1804:Deli Deli的相关文章

UVa 11233 - Deli Deli

题目:求所给单词的负数形式. 分析:模拟.直接按章题意分情况求解即可. 说明:按语法也可以(⊙_⊙). #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> using namespace std; char word[22][22],maps[22][22],text[25]; int cmp(char *s, char c) { for (int i = 0

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

[转]The culture name list in C#

Culture Names [C#] This example shows how to get all culture names in the .NET Framework. Use static methodCultureInfo.Get­Cultures. To get associated specific culture use static method CultureInfo.Cre­ateSpecificCul­ture. Following code is modified

归并排序求逆序数(POJ 1804,POJ 2299,HDU 4911)

首先,明确两个概念: 逆序对:数列a[1],a[2],a[3]-中的任意两个数a[i],a[j] (i<j),如果a[i]>a[j],那么我们就说这两个数构成了一个逆序对. 逆序数:一个数列中逆序对的总数. 例题一:POJ 1804.   点击打开链接 解题思路:每次交换只能减少一个逆序,而且必定能减少一个逆序,从而问题就转换为求逆序个数了.这题数据规模很小,暴力可过. 我这里提供了用Merge_sort的方法求解逆序数,时间复杂度为O(nlogn). 关于归并排序:归并排序是将数列a[l,h

HDU分类

模拟题, 枚举 1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 12

HDU——PKU题目分类

HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201

hdu 3944 dp?

DP? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 128000/128000 K (Java/Others)Total Submission(s): 1804    Accepted Submission(s): 595 Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0,1,2,-a