蓝桥杯-P0701(java)

问题描述

编写一个函数RegularPlural,其功能是实现一个英文单词的复数形式。复数的规则为:
  (1) 如果单词末尾为s,x,z,ch或sh,则在后面加es
  (2) 如果单词末尾为y,且前一个字母为辅音(除a, e, i, o, u以外的其它情况),则把y改成ies。
  (3) 如果是其它情形,一律在后面加s。
  编写测试程序,输入一个长度小于20的单词,输出该单词的复数形式。

样例输入

box

样例输出

boxes

我的思路:

没啥好说,就硬写。

代码:

package LanQiao;

import java.io.BufferedInputStream;
import java.util.Scanner;

/**
 * Copyright (C), 2019-2021, Kkoo
 * Author: kkoo
 * Date: 2021/11/21 5:33 下午
 * FileName: P0701
 */
public class P0701 {
    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedInputStream(System.in));
        char[] str = in.nextLine().toCharArray();
        if ((str[str.length - 1] == 's') || (str[str.length - 1] == 'x') || (str[str.length - 1] == 'z') || (str[str.length - 2] == 'c' && str[str.length - 1] == 'h') || (str[str.length - 2] == 's' && str[str.length - 1] == 'h')) {
            for (char t : str) {
                System.out.print(t);
            }
            System.out.print("es");
        } else if (str[str.length - 1] == 'y' && (str[str.length - 2] != 'a' && str[str.length - 2] != 'e') && str[str.length - 2] != 'i' && str[str.length - 2] != 'o' && str[str.length - 2] != 'u') {
            for (int i = 0; i < str.length - 1; i++) {
                System.out.print(str[i]);
            }
            System.out.print("ies");
        } else {
            for (int i = 0; i < str.length; i++) {
                System.out.print(str[i]);
            }
            System.out.print("s");
        }
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值