HDU1804 Deli Deli
来源:互联网 发布:林俊杰 知乎 编辑:程序博客网 时间:2024/06/08 19:28
Deli Deli
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1399 Accepted Submission(s): 761
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 ith line is the plural form of the ith input word.
Sample Input
3 7rice ricespaghetti spaghettioctopus octopiricelobsterspaghettistrawberryoctopuspeachturkey
Sample Output
ricelobstersspaghettistrawberriesoctopipeachesturkeys
这题WA得想吐,一直没找到错哪,然后重写一遍又过了,这题真恶心。
#include <stdio.h>#include <string.h>struct Node{char str1[22], str2[22];} irr[22];char str[26]; int len, m, n;int find(){for(int i = 0; i < m; ++i)if(!strcmp(str, irr[i].str1)) return i;return -1;}bool yuanyin(char ch){char *yuan = "aeiou";for(int i = 0; i < 5; ++i)if(ch == yuan[i]) return true;return false;}void check(){int flag = find();if(flag > -1){puts(irr[flag].str2); return;}if(str[len-1] == 'o' || str[len-1] == 's' || str[len-1] == 'x'){strcat(str, "es"); puts(str); return;}if(len > 1 && (str[len-1] == 'h' && (str[len-2] == 's' || str[len-2] == 'c'))){strcat(str, "es"); puts(str); return;}if(len > 1 && str[len-1] == 'y' && !yuanyin(str[len-2])){str[len-1] = '\0'; strcat(str, "ies"); puts(str); return;}strcat(str, "s"); puts(str);}int main(){while(scanf("%d%d", &m, &n) == 2){for(int i = 0; i < m; ++i)scanf("%s%s", irr[i].str1, irr[i].str2);while(n--){scanf("%s", str);len = strlen(str);check();}}return 0;}
0 0
- HDU1804 Deli Deli
- 【端午小练】HDU1804-Deli Deli
- Deli Deli
- HDU 1804 Deli Deli
- poj 3366 Deli Deli
- hdu_1804 Deli Deli
- UVa 11233 - Deli Deli
- HDU 1804 Deli Deli
- BNUOJ 1010 Deli Deli
- HDU 1804:Deli Deli
- HDU_1804Deli Deli
- 【TOJ 2911】 Deli Deli【水题】
- POJ 3366 Deli Deli 可能会
- HDU——1804 Deli Deli
- [字典树] HDU 1804 - Deli Deli
- 杭电OJ 1803 Deli Deli
- HDU 1804 Deli Deli (String)
- Deli Deli(简单的STL + 字符串)
- 《C++标准程序库》读书笔记一
- 文件系统拷贝到asm上
- 微信支付接口开发流程
- MC, MCMC, Gibbs采样 原理&实现(in R)
- Asp.net网站用户登陆验证码
- HDU1804 Deli Deli
- R语言 基本数据分析
- LUA模块
- epoll中listen socket的触发模式选择
- C++类中,应该注意的几个题目
- “蓝桥杯”记录
- C++程序设计之四书五经
- jQuery Easyui form 提交验证 与 json数据返回结果的处理
- 《dreamweaver8.0视频课程》笔记