sgu 460. Plural Form of Nouns

本文介绍了一个简单的程序,用于将英语名词从单数形式转换为复数形式。该程序遵循特定的转换规则,例如以 ch、x、s 或 o 结尾的单词加 es,以 f 或 fe 结尾的单词变为 ves,以 y 结尾的单词变为 ies,其余情况直接加 s。文章提供了完整的 C++ 实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

460. Plural Form of Nouns
Time limit per test: 0.25 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard

In the English language, nouns are inflected by grammatical number — that is singular or plural. In this problem we use a simple model of constructing plural from a singular form. This model doesn't always make English plural forms correctly, but it works in most cases. Forget about the real rules you know while solving the problem and use the statement as a formal document.

You are given several nouns in a singular form and your program should translate them into plural form using the following rules:


  • If a singular noun ends with 
    ch
    x
    s
    o
     the plural is formed by adding 
    es
    . For example, 
    witch
     -> 
    witches
    tomato
     -> 
    tomatoes
    .

  • If a singular noun ends with 
    f
     or 
    fe
    , the plural form ends with 
    ves
    . For example, 
    leaf
     -> 
    leaves
    knife
     -> 
    knives
    . Pay attention to the letter 
    f
     becoming 
    v
    .

  • Nouns ending with 
    y
     change the ending to 
    ies
     in plural. For example, 
    family
     -> 
    families
    .

  • In all other cases plural is formed by adding 
    s
    . For example, 
    book
     -> 
    books
    .


Input
The first line of input contains a single positive integer n (1 ≤ n ≤ 10) — the number of words to be processed. The following n lines contain one word each. A word consists from 2 to 25 lowercase Latin letters. It is not guaranteed that the given words are real English words from vocabulary.

Output
Print n given words in their plural forms on separate lines. Keep the words in the same order as they are given in the input. 

Example(s)
sample input
sample output
3
contest
hero
lady
contests
heroes
ladies


变复数形式

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

char a[30];

void solve(){
    int n;
    scanf("%d",&n);
    while (n--){
        scanf("%s",a);
        int len=strlen(a);
        if(a[len-1]=='o'||a[len-1]=='s'||a[len-1]=='x'||(a[len-2]=='c'&&a[len-1]=='h')){
            a[len]='e';
            a[len+1]='s';
            a[len+2]='\0';
        }
        else if(a[len-1]=='f'){
            a[len-1]='v';
            a[len]='e';
            a[len+1]='s';
            a[len+2]='\0';
        }
        else if(a[len-2]=='f'&&a[len-1]=='e'){
            a[len-2]='v';
            a[len-1]='e';
            a[len]='s';
            a[len+1]='\0';
        }
        else if(a[len-1]=='y'){
            a[len-1]='i';
            a[len]='e';
            a[len+1]='s';
            a[len+2]='\0';
        }
        else{
            a[len]='s';
            a[len+1]='\0';
        }

        printf("%s\n",a);
    }
}




int main() {


#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    solve();


    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值