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

题意:

输出单词的复数形式。

有些是特殊变化的,事先给你。

如果是以辅音字母加y结尾的,改y为i再加es。

如果是以”o”, “s”, “ch”, “sh” or “x”,结尾的,直接加es。

其他的直接加s。



用Map存储特殊的变化单词。再模拟处理就OK。


import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Scanner; public class Main{ public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n =sc.nextInt();
int m =sc.nextInt();
Map<String, String> map = new HashMap<String, String>();
for(int i=0;i<n;i++){
String a = sc.next();
String b = sc.next();
map.put(a, b);
}
for(int i=0;i<m;i++){
String str=sc.next();
if(map.get(str)!=null){
System.out.println(map.get(str));
}else{
char a = str.charAt(str.length()-2);
char b= str.charAt(str.length()-1);
if(a!='a'&&a!='e'&&a!='i'&&a!='o'&&a!='u'&&str.charAt(str.length()-1)=='y'){
for(int k=0;k<str.length()-1;k++){
System.out.print(str.charAt(k));
}
System.out.println("ies");
}else if((a=='c'&&b=='h')||(a=='s'&&b=='h')||b=='o'||b=='s'||b=='x'){
for(int k=0;k<str.length();k++){
System.out.print(str.charAt(k));
}
System.out.println("es");
}else{
for(int k=0;k<str.length();k++){
System.out.print(str.charAt(k));
}
System.out.println("s");
}
}
}
}
}
}

HDOJ/HDU 1804 Deli Deli(英语单词复数形式~)的更多相关文章

  1. hdu 2243 考研路茫茫——单词情结(AC自动+矩阵)

    考研路茫茫——单词情结 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. java常用英语单词

    abstract (关键字) 抽象 ['.bstr.kt] access vt.访问,存取 ['.kses]'(n.入口,使用权) algorithm n.算法 ['.lg.riem] annotat ...

  3. 英语单词character

    来源——tr帮助说明 TR() User Commands TR() NAME tr - translate or delete characters SYNOPSIS tr [OPTION]... ...

  4. 英语单词custom

    custom 来源——xshell快捷键 翻译 n. 习惯,惯例:风俗:海关,关税:经常光顾:[总称](经常性的)顾客 adj. (衣服等)定做的,定制的 高中 | 初中 词源 英语单词custom含 ...

  5. Java的实验程序之输出单个文件中的前 N 个最常出现的英语单词

    日期:2018.10.11 星期四 博客期:016 题目:输出单个文件中的前 N 个最常出现的英语单词,并输出到文本文件中 在程序运行之前,我试着先写了字符的字母的总结,加载代码如下: //如下是第一 ...

  6. HDOJ(HDU).1412 {A} + {B} (STL SET)

    HDOJ(HDU).1412 {A} + {B} (STL SET) 点我挑战题目 题意分析 大水题,会了set直接用set即可. 利用的是set的互异性(同一元素有且仅有一项). #include ...

  7. HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)

    HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...

  8. HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)

    HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和) 点我挑战题目 题意分析 根据数据范围和询问次数的规模,应该不难看出是个数据结构题目,题目比较裸.题中包括以下命令: 1.Add(i ...

  9. HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)

    HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...

随机推荐

  1. 九度OJ 1066 字符串排序

    题目地址:http://ac.jobdu.com/problem.php?pid=1066 题目描述: 输入一个长度不超过20的字符串,对所输入的字符串,按照ASCII码的大小从小到大进行排序,请输出 ...

  2. .NET 中String类功能分类概述

    一.比较功能 String.Compare: 成员函数 返回值 功能 String.Compare 小于零.零.大于零. 1.比较两个字符串的大小(按照一定规则) 2.比较两个字符串中子字符串的大小. ...

  3. 收藏一个匹配html内容的文章

    http://blog.csdn.net/donglynn/article/details/35788879

  4. Python Tips and Traps(一)

    1.如果想得到一个列表的index和内容,可以通过enumerate快速实现 drinks = ['coffee','tea', 'milk', 'water'] for index, drink i ...

  5. C# 拷贝数组的几种方式

    突然学到了,所以就放到博客上来共享一下,权当是学习日记吧. 首先说明一下,数组是引用类型的,所以注意不要在复制时复制了地址而没有复制数值哦! 其实在复制数组的时候,一定要用new在堆中开辟一块新的空间 ...

  6. 集成Facebook和Twitter的Model动画-b

    这个动画.  感谢大神分享 JPPopPresentAnimation.gif 要实现这个功能分两步走:第一步,先实现这个动画.第二步,0行代码集成到项目.也就是,你不用改原有项目的任何代码,只要把写 ...

  7. 30年的Hello world

    30 年的 Hello world 转载自:http://www.admin10000.com/document/2398.html 最近我在7月4日这一天所在的那周休假了.休假期间,我利用大把的时间 ...

  8. EXCEL : We can't do that to a merged cell.

  9. jquery mobile backbone

    http://www.appliness.com/getting-started-with-html-mobile-application-development-using-jquery-mobil ...

  10. Swift 中的静态方法继承

    Base and Derived Classes: class BaseClass{ class func staticMethod(){ println("BaseClass.static ...