Codeforces Round #434 (Div.2) - C - Did you mean...
2017-09-18 11:08
357 查看
C. Did you mean...
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 3000letters.
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
output
input
output
input
output
题意:
1.有一个长度在1-3000的字符串
2.将所给串分为一个或多个合法串
合法串:串内不存在三个或三个以上的连续辅音字母,所有连续辅音字母均相同除外
3.辅音字母:除元音字母外的所有字母;元音字母:’a’,’e’,’i’,’o’,’u’
4.在分割时使用一个空格分割,要尽量少的分割。
题解:
从左到右遍历,在每个位置判断以下几点:
1.是否为辅音字母
(1).是
.下一字母是否为辅音字母(否则跳过)
.下一字母是否与该点字母相同
.该点为第几个辅音字母
(2).否
清零连续辅音数,标记字母相同
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
char s[3010],ans[5050];
int main()
{
scanf("%s",s);
int cnt = 0,same = 1,k=0,len = (int)strlen(s);
for(int i=0;i<len;i++)
{
ans[k++] = s[i];
if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u') cnt = 0,same = 1;
else
{
cnt++;
int pos = i+1;
if(pos==len||s[pos]=='a'||s[pos]=='e'||s[pos]=='i'||s[pos]=='o'||s[pos]=='u') continue;
if(s[pos]!=s[pos-1]) same = 0;
if(same) continue;
if(cnt>=2)
{
ans[k++] = ' ';
cnt = 0;
same = 1;
}
}
}
puts(ans);
return 0;
}
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 3000letters.
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
output
hell no
input
abacaba
output
abacaba
input
asdfasdf
output
asd fasd f
题意:
1.有一个长度在1-3000的字符串
2.将所给串分为一个或多个合法串
合法串:串内不存在三个或三个以上的连续辅音字母,所有连续辅音字母均相同除外
3.辅音字母:除元音字母外的所有字母;元音字母:’a’,’e’,’i’,’o’,’u’
4.在分割时使用一个空格分割,要尽量少的分割。
题解:
从左到右遍历,在每个位置判断以下几点:
1.是否为辅音字母
(1).是
.下一字母是否为辅音字母(否则跳过)
.下一字母是否与该点字母相同
.该点为第几个辅音字母
(2).否
清零连续辅音数,标记字母相同
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
char s[3010],ans[5050];
int main()
{
scanf("%s",s);
int cnt = 0,same = 1,k=0,len = (int)strlen(s);
for(int i=0;i<len;i++)
{
ans[k++] = s[i];
if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u') cnt = 0,same = 1;
else
{
cnt++;
int pos = i+1;
if(pos==len||s[pos]=='a'||s[pos]=='e'||s[pos]=='i'||s[pos]=='o'||s[pos]=='u') continue;
if(s[pos]!=s[pos-1]) same = 0;
if(same) continue;
if(cnt>=2)
{
ans[k++] = ' ';
cnt = 0;
same = 1;
}
}
}
puts(ans);
return 0;
}
相关文章推荐
- Codeforces Round #434 Did you mean...
- Codeforces Round #423 Div.2 A B C D E F
- Codeforces Round #410 (Div.2) C.Mike and gcd problem-数学
- Codeforces Round #410 (Div.2) D.Mike and distrubition-构造
- Codeforces Round 389 Div.2 B. Santa Claus and Keyboard Check(模拟)
- codeforces round #234 div.2 A
- Codeforces Round #184 (Div.2)
- Codeforces Round #427 (Div.2) A
- codeforces Intel Code Challenge Final Round (div.1 + div.2 combined)
- codeforces Round 256(Div.2)D.Multiplication Table(二分)
- Codeforces Round 389 Div.2 B. Santa Claus and Keyboard Check(模拟)
- Codeforces Round #434 Which floor?
- Codeforces Round #212 (Div.2)
- codeforces round #236 div.2 B
- Codeforces Round #FF (Div.2 )(C,D)
- Codeforces Round #360 (Div. 2) E The Values You Can Make(DP)
- Codeforces Round 389 Div.2 B. Santa Claus and Keyboard Check(模拟)
- codeforces Round#158 Div.2 小结
- 【codeforces 434 div 1 A】Did you mean...
- CodeForces Round #290 Div.2