hd acm steps 1.2.8

本文介绍了一个用于转换单词为特定格式的Vowel-Counting-Word(VCW)算法,其中包括输入测试案例并输出相应的VCW。算法区分大小写字母,并遵循特定规则进行转换。

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

Vowel Counting

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2392 Accepted Submission(s): 1326
 
Problem Description
The "Vowel-Counting-Word"(VCW), complies with the following conditions.
Each vowel in the word must be uppercase. 
Each consonant (the letters except the vowels) must be lowercase.
For example, "ApplE" is the VCW of "aPPle", "jUhUA" is the VCW of "Juhua".
Give you some words; your task is to get the "Vowel-Counting-Word" of each word.
 
Input
The first line of the input contains an integer T (T<=20) which means the number of test cases.
For each case, there is a line contains the word (only contains uppercase and lowercase). The length of the word is not greater than 50.
 
Output
For each case, output its Vowel-Counting-Word.
 
Sample Input
4
XYz
application
qwcvb
aeioOa 
 
Sample Output
xyz
ApplIcAtIOn
qwcvb
AEIOOA
 
/*
两点需要注意:
1.bool函数一定要true和false都要返回,而不要只返回其中之一,否则很容易出错;
2.读入的一点技巧<img src="https://img-blog.youkuaiyun.com/20140914211803562?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveWFuZ196b25nanVu/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />这里在读入数字之后一定要用getchar()函数读掉其后的空格或回车,在读入一行字符串,否则出错!
*/
//@auther Yang Zongjun
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>

using namespace std;
#define PI acos(-1.0)
#define EPS 1e-8
const int MAXN = 55;
const int INF = 2100000000;
char c[MAXN];

bool isXiaoXie_Yuanyin(char cha)
{
    if(cha=='a' || cha=='e' || cha=='i' || cha=='o' || cha=='u') return true;
    else return false;//开始时候没写else return false导致错误,每次他默认返回true,
    //导致只执行这一个bool函数,下面的都不执行了。
    //但好像有时候bool函数它默认返回false,所以每次写bool函数时一定要return true和return false都要写
    //千万不要只写其中之一,这样很容易出错的!!!
}

bool isDaxie_yuanyin(char cha)
{
    if(cha=='A' || cha=='E' || cha=='I' || cha=='O' || cha=='U') return true;
    else return false;
}

bool isDaxie_fuyin(char cha)
{
    if('B'<=cha&&cha<='Z' && cha!='E' && cha!='I' && cha!='O' && cha!='U')return true;
    else return false;
}

int main()
{
//    freopen("C:/Users/Administrator/Desktop/input.txt", "r", stdin);
    int n;
    while(~scanf("%d", &n))
    {
        getchar();/*这里有一个常见技巧:就是先读入一个整数,但后面要读入一行字符串,
        这样的话一定要加一个getchar()函数将整数后面的空格或者是回车读掉,否则极有可能出错!!!
        */
        while(n--)
        {
            //memset(c, 0, sizeof(c));
        gets(c);
        int len = strlen(c);
        //cout << c << " " << len << endl;
        for(int i = 0; i < len; i++)
        {
            if(isXiaoXie_Yuanyin(c[i])) printf("%c", (char)(c[i]-32) );
            else if(isDaxie_yuanyin(c[i])) printf("%c", (char)(c[i]));
            else if(isDaxie_fuyin(c[i])) printf("%c", (char)(c[i] + 32));
            else printf("%c", (char)(c[i]));
            if(i == len - 1) printf("\n");
        }
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值