关闭

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

标签: javaacm
6303人阅读 评论(0) 收藏 举报
分类:

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");
                    }
                }
            }
        }
    }
}
1
0
查看评论

HDU——1804 Deli Deli

题意:将规则动词化为复数形式,将不规则动词化为对应的
  • u014086857
  • u014086857
  • 2014-11-05 19:07
  • 265

HDU 1804:Deli Deli

Deli Deli Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1708 ...
  • lin14543
  • lin14543
  • 2015-08-27 16:57
  • 435

HDU 1804 Deli Deli

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1804 Deli Deli Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768...
  • u013615904
  • u013615904
  • 2015-01-20 17:17
  • 444

HDU 1804 Deli Deli (String)

模拟题,顺便联系一下几个函数 #include #include #include #include #include #include #include using namespace std; int main(){ int n,m; cin>>n>>m; ma...
  • qq_33193309
  • qq_33193309
  • 2017-09-24 14:59
  • 51

[字典树] HDU 1804 - Deli Deli

字典树裸题,建树的时候,给每个节点加一个字符串
  • x_iaow_ei
  • x_iaow_ei
  • 2014-11-17 11:06
  • 598

BNUOJ 1010 Deli Deli

由于项目和学习等原因,HK同学最近经常到一些外国文献。结果,他发现,懒惰而且甚至略微有点愚蠢的部分外国编辑居然连英语单词的单数形式变复数形式都处理不好(- -!这个是事实)……这让思维一贯严谨的HK同学很不爽,他决定写一个程序来解决这个问题。 下面是关于如何使复数形式的一个描述:  ...
  • Zidane_2014
  • Zidane_2014
  • 2015-05-16 23:45
  • 425

hdu_1804 Deli Deli

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1804 分析:            用STL中map容器,map记录特殊单词的变换,map 标记特殊单...
  • u010885608
  • u010885608
  • 2013-08-17 11:40
  • 505

HDU1804 Deli Deli

Deli Deli Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1399 ...
  • u012846486
  • u012846486
  • 2014-06-02 20:00
  • 976

Deli Deli

Deli Deli Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1227 ...
  • wenlovingliu
  • wenlovingliu
  • 2013-04-29 21:14
  • 429

杭电OJ 1803 Deli Deli

Problem Description Mrs. Deli is running the delicatessen store "Deli Deli". Last year Mrs. Deli has decided to expand her business and buil...
  • chen_minghui
  • chen_minghui
  • 2016-07-25 15:31
  • 186
    个人资料
    • 访问:2054693次
    • 积分:26844
    • 等级:
    • 排名:第251名
    • 原创:680篇
    • 转载:26篇
    • 译文:0篇
    • 评论:569条
    个人信息:
    博客专栏
    友情链接:
    文章分类
    最新评论