CF938A 【Word Correction】【題解】
題目背景
給一個長為 的字串,當有兩個母音字母相鄰時,刪除後一個母音,輸出修改後的字串。(注: , , , , , 為母音字母)
題目描述
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 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 n ( 1<=n<=100 1<=n<=100 ) — the number of letters in word s s before the correction.
The second line contains a string s s consisting of exactly n n lowercase Latin letters — the word before the correction.
輸出格式:
Output the word s s after the correction.
輸入輸出樣例
輸入樣例#1:
5
weird
輸出樣例#1:
werd
輸入樣例#2:
4
word
輸出樣例#2:
word
輸入樣例#3:
5
aaeaa
輸出樣例#3:
a
思想:如果當前字母與前一個都是母音字母,就什麼也不做,否則輸出當前字母
話不多說,程式碼有解釋
如下:
#include<iostream>
using namespace std;
char s;
int main(){
int n,m=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>s;
if(s!='a' && s!='e'&& s!='i' && s!='o' && s!='u' && s!='y')
cout<<s,m=0;
else if(m) continue;
else cout<<s,m=1;
}
return 0;
}