Codeforces 938.A Word Correction
1 second
256 megabytes
standard input
standard output
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 isanother 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.
5
weird
werd
4
word
word
5
aaeaa
a
Explanations of the examples:
- There is only one replace: weird
werd;
- No replace needed since there are no two consecutive vowels;
- aaeaa
aeaa
aaa
aa
a.
题目大意:给一个字符串,如果有两个连续的元音字母,则删掉后一个,一直进行这种操作,求最后的字符串.
分析:一个一个去枚举删就比较麻烦了,一个比较好的做法是用栈维护,枚举第i个位置,与栈顶的字符比较,看是否符合要求.最后输出栈里的字符串就好了.
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include <cmath> using namespace std; typedef long long LL; char s[],ans[];
int tot,n; bool check(char a,char b)
{
bool flag1 = false,flag2 = false;
if (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u' || a == 'y')
flag1 = true;
if (b == 'a' || b == 'e' || b == 'i' || b == 'o' || b == 'u' || b == 'y')
flag2 = true;
if (flag1 && flag2)
return true;
return false;
} int main()
{
scanf("%d",&n);
scanf("%s",s + );
for (int i = ; i <= n; i++)
{
if (!tot)
ans[++tot] = s[i];
else
{
if (!check(ans[tot],s[i]))
ans[++tot] = s[i];
}
}
for (int i = ; i <= tot; i++)
printf("%c",ans[i]); return ;
}
Codeforces 938.A Word Correction的更多相关文章
- Codeforces 938 D. Buy a Ticket (dijkstra 求多元最短路)
题目链接:Buy a Ticket 题意: 给出n个点m条边,每个点每条边都有各自的权值,对于每个点i,求一个任意j,使得2×d[i][j] + a[j]最小. 题解: 这题其实就是要我们求任意两点的 ...
- Codeforces 938.D Buy a Ticket
D. Buy a Ticket time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces 938.C Constructing Tests
C. Constructing Tests time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces 938.B Run For Your Prize
B. Run For Your Prize time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces 938 正方形方格最多0/1 足球赛dijkstra建图
A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...
- CF938A Word Correction 题解
Content 有一个长度为 \(n\) 的,只包含小写字母的字符串,只要有两个元音字母相邻,就得删除后一个元音字母(\(\texttt{a,e,i,o,u,y}\) 中的一个),请求出最后得到的字符 ...
- Educational Codeforces Round 38 (Rated for Div. 2)
这场打了小号 A. Word Correction time limit per test 1 second memory limit per test 256 megabytes input sta ...
- 【Educational Codeforces Round 38 (Rated for Div. 2)】 Problem A-D 题解
[比赛链接] 点击打开链接 [题解] Problem A Word Correction[字符串] 不用多说了吧,字符串的基本操作 Problem B Run for your prize[贪心] ...
- CodeForces 176B Word Cut dp
Word Cut 题目连接: http://codeforces.com/problemset/problem/176/C Description Let's consider one interes ...
随机推荐
- Q&A - 如何获取ip地址所在地
获取其IP地址后,传入以下URL,并请求该URL,该请求会响应一个JSON格式的数据包,该IP地址的所在地均在这个数据包内 http://int.dpool.sina.com.cn/iplooku ...
- jdbc学习笔记01
回顾: day01-03,在上一篇文章文末 day04: 分组 group by 统计每个部门的平均工资: select deptno,avg(sal) from emp group by deptn ...
- ZOJ3640 概率DP
Background If thou doest well, shalt thou not be accepted? and if thou doest not well, sin lieth at ...
- RHCE考试
RHCSA_PDF版传送门:https://files.cnblogs.com/files/zhangjianghua/RHCSA%E8%AF%95%E9%A2%98.pdf RHCE_PDF版传送门 ...
- 在MAC下使用Robotframework+Selenium2【第二枪】如何处理Table点击指定记录
1.通过关键字Get Matching Xpath Count获取table中的记录 2.遍历Table所有记录 3.判断记录是否符合条件,做点击操作
- issubclasss/type/isinstance/callable/super
issubclass() : 方法用于判断第一个参数是否是第二个参数的子子孙孙类. 语法:issubclass(sub, super) 检查sub类是否是 super 类的派生类 class A: p ...
- windows下进程间通信(转)
摘 要 随着人们对应用程序的要求越来越高,单进程应用在许多场合已不能满足人们的要求.编写多进程/多线程程序成为现代程序设计的一个重要特点,在多进程程序设计中,进程间的通信是不可避免的.Microsof ...
- Maven学习 (三) 使用m2eclipse创建web项目
1.首先确认你的eclipse已经安装好m2eclipse的环境,可以参照上两篇Maven学习内容 2.新建一个maven的项目 3.下一步默认配置,使用默认的工作空间,或者你可以自己选择其他的空间 ...
- (原)SpringMVC全注解不是你们那么玩的
前言:忙了段时间,忙得要死要活,累了一段时间,累得死去活来. 偶尔看到很多零注解配置SpringMVC,其实没有根本的零注解. 1)工程图一张: web.xml在servlet3.0里面已经被注解完全 ...
- java中继承的概念
继承是类的三大特性之一,是java中实现代码重用的重要手段之一. java中只支持单继承,即每个类只能有一个父类. 继承表达的是is a的关系,或者说一种特殊和一般的关系. ...