当前位置: 首页 > news >正文

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");
                    }
                }
            }
        }
    }
}

相关文章:

  • 原型链的理解
  • 关于图片加载非常爽的一个三方控件 fresco,一个三fresco
  • 深浅拷贝的理解
  • Django里自定义用户登陆及登陆后跳转到登陆前页面的实现
  • PHP导入Excel和导出数据为Excel文件
  • DOM事件模型 DOM事件流 自定义事件(模拟事件)
  • 计算几何初步-三点顺序
  • 模块化,简单一点
  • 蓝牙(BLE)应用框架接口设计和应用开发——以TI CC2541为例
  • GET和POST的区别,何时使用POST?
  • Android 之内容提供程序(Content Provider)
  • 同源策略 跨域
  • matlab基本粒子群算法实现(三)
  • saltstack知道这些就很好用了
  • Es6中常用的新特性
  • 自己简单写的 事件订阅机制
  • [ 一起学React系列 -- 8 ] React中的文件上传
  • C++回声服务器_9-epoll边缘触发模式版本服务器
  • Git初体验
  • java小心机(3)| 浅析finalize()
  • Java知识点总结(JavaIO-打印流)
  • leetcode386. Lexicographical Numbers
  • open-falcon 开发笔记(一):从零开始搭建虚拟服务器和监测环境
  • Web标准制定过程
  • 分享自己折腾多时的一套 vue 组件 --we-vue
  • 收藏好这篇,别再只说“数据劫持”了
  • 数组大概知多少
  • 移动互联网+智能运营体系搭建=你家有金矿啊!
  • 原生 js 实现移动端 Touch 滑动反弹
  • TPG领衔财团投资轻奢珠宝品牌APM Monaco
  • ​2021半年盘点,不想你错过的重磅新书
  • ​水经微图Web1.5.0版即将上线
  • # 深度解析 Socket 与 WebSocket:原理、区别与应用
  • #NOIP 2014# day.1 T3 飞扬的小鸟 bird
  • $redis-setphp_redis Set命令,php操作Redis Set函数介绍
  • (ros//EnvironmentVariables)ros环境变量
  • (附源码)springboot金融新闻信息服务系统 毕业设计651450
  • (附源码)基于SpringBoot和Vue的厨到家服务平台的设计与实现 毕业设计 063133
  • (求助)用傲游上csdn博客时标签栏和网址栏一直显示袁萌 的头像
  • (十五)Flask覆写wsgi_app函数实现自定义中间件
  • (转)编辑寄语:因为爱心,所以美丽
  • (转载)虚幻引擎3--【UnrealScript教程】章节一:20.location和rotation
  • .NET 除了用 Task 之外,如何自己写一个可以 await 的对象?
  • .Net 知识杂记
  • .net6+aspose.words导出word并转pdf
  • .NET使用HttpClient以multipart/form-data形式post上传文件及其相关参数
  • .net网站发布-允许更新此预编译站点
  • .net之微信企业号开发(一) 所使用的环境与工具以及准备工作
  • /proc/vmstat 详解
  • @property括号内属性讲解
  • [ Linux ] Linux信号概述 信号的产生
  • [@Controller]4 详解@ModelAttribute
  • [2013][note]通过石墨烯调谐用于开关、传感的动态可重构Fano超——
  • [④ADRV902x]: Digital Filter Configuration(发射端)
  • [AIR] NativeExtension在IOS下的开发实例 --- IOS项目的创建 (一)