Codeforces Educational 38 A. Word Correction

介绍了一种文本编辑器中的单词校正算法,该算法会删除单词中出现的连续元音中的第一个元音,直至不再存在连续元音。文章提供了一个C++实现示例,用于演示如何应用此算法。

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

题目描述

Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.

Victor thinks that if a word contains two consecutive vowels, then it’s kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct.

You are given a word s. Can you predict what will it become after correction?

In this problem letters a, e, i, o, u and y are considered to be vowels.

输入

The first line contains one integer n (1 ≤ n ≤ 100) — the number of letters in word s before the correction.

The second line contains a string s consisting of exactly n lowercase Latin letters — the word before the correction.

输出

Output the word s after the correction.

样例

inputCopy
5
weird
output
werd
inputCopy
4
word
output
word
inputCopy
5
aaeaa
output
a

题意

把CD写完迷迷糊的这个辣鸡题不想写了,,,,
记录每个连续元音字母位置即可

AC代码

#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define CLR(a,b) memset(a,(b),sizeof(a))

const int MAXN = 1e6;
const int INF = 0x3f3f3f3f;
const LL INFLL = ~0ull>>1;
char ch[] = {'a', 'e', 'i', 'o', 'u','y'};
bool check(char ss)
{
    for(int i = 0; i < 6; i++)
        if(ss == ch[i])
            return true;
    return false;
}
vector<int> v;
int main()
{
    ios::sync_with_stdio(false),cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    bool flag = false;
    for(int i = 0; i < n; i++) {
        if(i > 0)
            if(check(s[i]) && check(s[i-1])) {
                v.push_back(i); flag = true;
            }

    }
    if(!flag) return cout << s << endl,0;
    for(int i=0,j=0; i < n; i++) {
        if(i == v[j])
            j++;
        else
            cout << s[i];
    }
    return  0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值