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. nginx 自定义代理返回 404

    在nginx的http段,加上一面的配置 proxy_intercept_errors on;//自定义代理返回的404错误提示

  2. mysql主从 1050错误

    在mysql从库上查询时出现如下错误 ...................... Last_Errno: 1050                    Last_Error: Error 'Tab ...

  3. Lambda Expression In Java

     题记在阅读JDK源码java.util.Collections的时候在UnmodifiableCollection类中看到了这么一段代码: public void forEach(Consumer& ...

  4. 《JavaScript高级程序设计》笔记(1):<script>元素

    使用<script>元素内部的JavaScript代码将从上至下依此解释.在使用<script>嵌入的JavasCript代码时,代码任何地方不能出现"</sc ...

  5. 学习JS

    原型是Js中非常重要的概念,每个函数(在Js里面函数也是对象)都有一个叫prototype即原型)的属性,不过在一般情况下它的值都是null,但它他有一项非常重要的功能就是所以实例都会共享它里面的属性 ...

  6. css的box-sizing:border-box有什么用

    css的box-sizing:border-box有什么用:视频说是多了的尺寸去掉了,适配box宽高

  7. 关于mac上的homebrew

    首先它的安装指令并不难: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/ ...

  8. 精通 Oracle+Python,第 1 部分:查询最佳应践

    原文链接:http://www.oracle.com/technetwork/cn/articles/dsl/mastering-oracle-python-1391323-zhs.html 在 Py ...

  9. [简历] JAVA 软件工程师

    首先,一份好的简历不光说明事实,更通过FAB模式来增强其说服力. Feature:是什么 Advantage:比别人好在哪些地方 Benefit:如果雇佣你,招聘方会得到什么好处 其次,写简历和写议论 ...

  10. zend studio 9.0.4 安装破解

    转载于 http://www.geekso.com/ZendStudio9-key 注册破解步骤第一步:如果已经安装过Zend Studio 9.0.4的,请打开Zend Studio 9.0.4,在 ...