Problem - 363C - Codeforces
Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).
Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.
The single line of the input contains word s, its length is from 1 to 200000 characters. The given words consists of lowercase English letters.
Print such word t that it doesn't contain any typos described in the problem statement and is obtained froms by deleting the least number of letters.
If there are multiple solutions, print any of them.
helloo
hello
woooooow
woow
The second valid answer to the test from the statement is "heloo".
#include<stdio.h>
#include<string.h>
#define N 200010
int main()
{
int i,j,len;
bool pre,now;
char str[N],ans[N];
while(scanf("%s",str)!=EOF)
{
pre=false;
now=false;
ans[0]=str[0];
for(len=i=1;str[i]!='\0';i++)
{
if(pre)
{
if(!now)
{
if(ans[len-1]==str[i]);
else
{
ans[len++]=str[i];
pre=false;
now=false;
}
}
else
{
if(ans[len-1]==str[i])
continue;
ans[len++]=str[i];
now=true;
}
}
else
{
if(ans[len-1]==str[i])
pre=true;
ans[len++]=str[i];
}
}
ans[len]='\0';
puts(ans);
}
return 0;
}