Codeforces 861 C. Did you mean... (模拟)
来源:互联网 发布:硬件温度监控软件 编辑:程序博客网 时间:2024/06/06 03:06
Description
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
the following words have typos: “hellno”, “hackcerrs” and “backtothefutttture”;
the following words don’t have typos: “helllllooooo”, “tobeornottobe” and “oooooo”.
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: ‘a’, ‘e’, ‘i’, ‘o’ and ‘u’. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn’t have any typos. If there are multiple solutions, print any of them.
Examples input
hellno
Examples output
hell no
题意
一个错误的单词是连续的辅音块中存在三个或以上的辅音字母(如果这些辅音字母是相同的除外),现在我们想用最少的空格将单词分为多个合理的子单词,输出分隔以后的结果。
思路
既然要用最少的空格分隔,那我们就要在所有的极限情况的末尾加空格,然后模拟判断一下即可。
AC 代码
#include<bits/stdc++.h>using namespace std;const int maxn = 1e5+10;char str[maxn];vector<int> ans;multiset<char> tmp;int main(){ int cnt = 0; cin>>str; int len = strlen(str); for(int i=0; i<len; i++) { if(str[i]!='a'&&str[i]!='o'&&str[i]!='e'&&str[i]!='i'&&str[i]!='u') { tmp.insert(str[i]); cnt++; if(*tmp.begin()!=*--tmp.end()) { if(cnt>=3) { ans.push_back(i-1); cnt = 1; tmp.clear(); tmp.insert(str[i]); } } } else { tmp.clear(); cnt = 0; } } for(int i=0; i<len; i++) { cout<<str[i]; if(ans.size()&&i==*ans.begin()) { cout<<" "; ans.erase(ans.begin()); } } return 0;}
- Codeforces 861 C. Did you mean... (模拟)
- Codeforces Round #434 Did you mean...
- CodeForces 858C Did you mean... 、 CodeForces 858D Polycarp's phone book!黑科技
- Codeforces858C Did you mean
- cf434A. Did you mean...
- Did You Mean: Lucene?-- Tom White
- unknown type name''",did you mean""
- adb的问题“No command 'adb' found, did you mean:”
- "Did you mean" feature with Apache Lucene Spell-Checker
- cocos2dx Unknown type name 'class'; did you mean 'Class'?问题解决!
- Unknown type name "CGRect",did you mean "Rect"?
- Unknown type name "CGRect",did you mean "Rect"?的解决方案
- Unknown type name "CGRect",did you mean "Rect"?的解决方案
- adb的问题“No command ‘adb’ found, did you mean:”
- Unknown type name 'class'; did you mean 'Class'
- Unknown type name 'class'; did you mean 'Class'? 解决方案
- cocoa Unknown type name 'class'; did you mean 'Class'? 问题解决
- DID YOU ?
- 错误( linker command failed with exit code 1)
- USACO2010Oct-Soda Machine
- Java泛型参数T详解
- 125. Valid Palindrome
- HDU5521 Meeting
- Codeforces 861 C. Did you mean... (模拟)
- 关于priority_queue的博客传送门
- js封装ajax
- Linux Mint 18 系统安装常见问题整理
- 若容器中包含了new创建的指针,一定要在析构前delete掉
- Machine learning for OpenCV 学习笔记 day6
- makefile命令
- 直流电机控制
- SQL实战题目(三)