HDOJ/HDU 1804 Deli Deli(英语单词复数形式~)

简介: HDOJ/HDU 1804 Deli Deli(英语单词复数形式~)

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:


If the word is in the list of irregular words replace it with the given plural.

Else if the word ends in a consonant followed by “y”, replace “y” with “ies”.

Else if the word ends in “o”, “s”, “ch”, “sh” or “x”, append “es” to the word.

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");
                    }
                }
            }
        }
    }
}
目录
相关文章
|
10月前
|
算法
算法编程(二十八):重新排列单词间的空格
算法编程(二十八):重新排列单词间的空格
72 0
|
算法 Java 索引
【洛谷算法题】P5704-字母转换【入门1顺序结构】
【洛谷算法题】P5704-字母转换【入门1顺序结构】
|
5月前
|
存储 算法 Java
数据结构与算法学习八:前缀(波兰)表达式、中缀表达式、后缀(逆波兰)表达式的学习,中缀转后缀的两个方法,逆波兰计算器的实现
前缀(波兰)表达式、中缀表达式和后缀(逆波兰)表达式的基本概念、计算机求值方法,以及如何将中缀表达式转换为后缀表达式,并提供了相应的Java代码实现和测试结果。
296 0
数据结构与算法学习八:前缀(波兰)表达式、中缀表达式、后缀(逆波兰)表达式的学习,中缀转后缀的两个方法,逆波兰计算器的实现
|
9月前
|
C语言
C语言学习记录——鹏哥字符分类函数、字符转换函数
C语言学习记录——鹏哥字符分类函数、字符转换函数
866 2
|
算法 C语言
(c语言)将一句话的单词进行倒置,标点不倒置(i like beijing.)
(c语言)将一句话的单词进行倒置,标点不倒置(i like beijing.)
203 0
|
10月前
数学基础从高一开始6、全称量词与存在量词
数学基础从高一开始6、全称量词与存在量词
77 0
|
算法 Java C++
【洛谷算法题】B2025-输出字符菱形【入门1顺序结构】
【洛谷算法题】B2025-输出字符菱形【入门1顺序结构】
每日一题,数组字符串的匹配问题
每日一题,数组字符串的匹配问题
|
存储 JavaScript IDE
程序员常用英文单词/英语单词/词汇表/变量名称
程序员常用英文单词/英语单词/词汇表/变量名称
357 0