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");
}
}
}
}
}
}
HDOJ/HDU 1804 Deli Deli(英语单词复数形式~)的更多相关文章
- hdu 2243 考研路茫茫——单词情结(AC自动+矩阵)
考研路茫茫——单词情结 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- java常用英语单词
abstract (关键字) 抽象 ['.bstr.kt] access vt.访问,存取 ['.kses]'(n.入口,使用权) algorithm n.算法 ['.lg.riem] annotat ...
- 英语单词character
来源——tr帮助说明 TR() User Commands TR() NAME tr - translate or delete characters SYNOPSIS tr [OPTION]... ...
- 英语单词custom
custom 来源——xshell快捷键 翻译 n. 习惯,惯例:风俗:海关,关税:经常光顾:[总称](经常性的)顾客 adj. (衣服等)定做的,定制的 高中 | 初中 词源 英语单词custom含 ...
- Java的实验程序之输出单个文件中的前 N 个最常出现的英语单词
日期:2018.10.11 星期四 博客期:016 题目:输出单个文件中的前 N 个最常出现的英语单词,并输出到文本文件中 在程序运行之前,我试着先写了字符的字母的总结,加载代码如下: //如下是第一 ...
- HDOJ(HDU).1412 {A} + {B} (STL SET)
HDOJ(HDU).1412 {A} + {B} (STL SET) 点我挑战题目 题意分析 大水题,会了set直接用set即可. 利用的是set的互异性(同一元素有且仅有一项). #include ...
- HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)
HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...
- HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)
HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和) 点我挑战题目 题意分析 根据数据范围和询问次数的规模,应该不难看出是个数据结构题目,题目比较裸.题中包括以下命令: 1.Add(i ...
- HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)
HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...
随机推荐
- 安装hadoop多节点 各种整理
ubuntu烧制usb启动盘链接: 点击打开链接https://help.ubuntu.com/community/Installation/FromUSBStick ubuntu磁盘分区: 点击打开 ...
- 【原创】Linux下获取命令的帮助与常用命令
Linux中的shell命令一般是执行步骤:用户在终端输入命令回车,系统内核会在当前用户的环境变量PATH中去读取环境变量的值 变量的值就是命令的路径,命令路径不只一个,于是系统会从这些路径中从左至右 ...
- PHP 自 5.2 到 5.6 中新增的功能详解
截至目前(2014.2), PHP 的最新稳定版本是 PHP5.5, 但有差不多一半的用户仍在使用已经不在维护 [注] 的 PHP5.2, 其余的一半用户在使用 PHP5.3 [注].因为 PHP 那 ...
- art.dialog 与 ajax 异步请求
上周写了一些代码,涉及到jquery异步请求,这里归纳总结下,希望对刚接触编程的同学有帮助. 主要习惯使用 art.dialog 框架,非常好用,在异步请求上,它提供了很多简便的方法. 加载使用art ...
- 2016030207 - sql50题练习(脚本)
我的mysql版本是5.下面是要进行sql练习题使用的脚本.脚本是我整理出来的,在我本地直接复制执行就可以使用! 参考网址是:http://blog.csdn.net/zhangyulin54321/ ...
- We7在政府门户中的应用
政府门户从传统的信息引导发展到现阶段的服务型门户,不论从角度转变上还是从平台选型上都跟以前有很大的不同,其更注重的是安全.扩展.易用和移动互联网几部分(当然这儿的注重是建立在已有政府门户电子政务三个板 ...
- Docker系列
Docker学习系列(五):Dockerfile文件 什么是Dockerfile? 它是一个名称为Dockerfile的文件 它是一个脚本文件,由一系列命令和参数构成 Dockerfile是自动构建d ...
- 图片Base64编码 简单使用
图片在线转换Base64,图片编码base64 http://tool.css-js.com/base64.html HTML5 + js <input type="file" ...
- [JavaScript] js实现简单的代码运行框
<script type="text/javascript">// <![CDATA[ function runCode(obj) { var winname = ...
- bzoj 3043: IncDec Sequence 模拟
3043: IncDec Sequence Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 248 Solved: 139[Submit][Statu ...