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:

  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");
                    }
                }
            }
        }
    }
}
时间: 2024-07-31 06:11:06

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

如何在Word 2013中翻译英语单词

Word2013中内置有双语词典,可以帮助用户将英语单词或句子翻译成中文(简体).中文(繁体).法语.德语.意大利语.日语等语言.用户可以借助Word2013文档窗口中的"信息检索"任务窗格很方便地翻译英文单词,操作步骤如下所述: 第1步,打开Word2013文档窗口,并切换到"审阅"选项卡.在"语言"分组中依次单击"翻译"→"翻译所选文字"按钮(可以不选中任何英语单词),如图2013080724所示. 图

借助ET表格背诵英语单词

正确朗读和记忆单词是学英语的重要环节.WPS 表格可以助您一臂之力,实现英语单词的点读机效果,并帮您背诵和默写英语单词,默写错误时及时给您提示. 具体步骤如下. 1.整理单词表,保存为文本文件. 2.导入到WPS表格. 打开ET,依次执行"导入数据"→"导入外部数据",弹出对话框: 点击"选择数据源",选择刚才得到的文本文件. 点击打开后,出现预览界面. 以下按提示和自己的需要执行. 3.实现点读机效果. 在文出有声工具栏中设置朗读方式为&quo

怎样在Word2013中翻译英语单词

  第1步,打开Word2013文档窗口,并切换到"审阅"选项卡.在"语言"分组中依次单击"翻译"→"翻译所选文字"按钮(可以不选中任何英语单词),如图1所示. 图1 选择"翻译所选文字"命令 第2步,打开"信息检索"任务窗格,在"搜索"编辑框中输入英语单词,并设置翻译方式为"将英语(美国)翻译成中文(中国)".设置完毕单击"开始搜索&q

Java英语学习—— Java 必背英语单词【必收藏】

对于刚开始学习Java编程的童鞋来说,会看到很多陌生的英语单词,甚至会因为这些英语单词对Java编程望而却步,尚小萌应众多童鞋的要求,整理出一份Java最常用的英语单词: Compile:编绎 Run:运行 Class:类 Object:对象 System:系统 System:系统 out:输出 print:打印 line:行  variable:变量 type:类型 static:静态的 array:数组 parameter:参数 method:方法 function:函数 public:公有

编程时学到的英语单词

编程时学到的英语单词 2015-09-02 学习openResty的时候,发现很多单词特别有意思.有些东西,是我们平常所用到的,但因为词汇量少的缘故所以很少使用. 1. We first create a separate directory for our experiments. You can use an arbitrary directory. Here for simplicity, we just use ~/work: mkdir ~/work cd ~/work mkdir l

[经典面试题][百度]电话号码对应英语单词

题目 现在有一个手机,手机上的键盘上有这样的对应关系,2对应"abc",3对应"def"-..手机里面有一个userlist用户列表,当我们输入942的时候出来拼音的对应可能是"xia","zha","xi","yi"等,当我们输入9264的时候出来是yang,可能是"样","杨","往"等,现在我们输入一个字符串数字,比如92

聊聊程序员如何学习英语单词:写了一个记单词的小程序

背景: 关于英文对程序员的重要性,就不多说了! 英语的学习,有很多,今天也不聊多,只聊英语单词! 关于单词的记忆,找过很多方法,下载过很多软件. 如图(其它不好用的都卸载了): 上图算是我以前用过软件,注意,是以前哦~~~ 意思就是没有坚持下来~~~~ 随时间的推移,最后它们还是被我遗忘了~~~ 为什么???不能:坚持!坚持!坚持! 学习思考: 一直在找方法: 1:下载过联想记忆法.背文章记单词,词根,各种视频~~~ 2:连单词的数据库都网上下载了一份了,期望从数据库的直接记忆单词快些~~~ 通

单词勘误-word 中自动检测英语单词是否正确的功能是如何实现的?

问题描述 word 中自动检测英语单词是否正确的功能是如何实现的? word中输入错误的英语单词后,会显示红色波浪线.它是如何检测到拼写错误的? 解决方案 它内置一个词典数据库,比较你的输入是否在词典上能查到.如果查不到,就视作是错误的. 一些术语和专有名词,比如人名地名,因为也不在词典上,所以即使你没有写错,也会被标记出来的. 解决方案二: 网上有word list,google下就有 大约10万的单词表足够了.

数据称Twitter成09年最热英语单词

12月1日消息,据国外媒体报道,全球语言监测机构(Global Language Monitor,以下简称"GLM")周一公布的数据显示,微型博客"Twitter"成为2009年最热门的英语单词. GLM主要根据语言在全球范围内的使用情况,评出了2009年最热门英语词汇.结果,"Twitter"战胜诸多流行词汇而高居榜首. 这与微软给出的统计结果基本一致,据微软日前公布的2009年10大热门搜索关键词显示,已故流行巨星迈克尔·杰克逊(Michae